P
pol_c
I am fairly new to asp's and .Net and I would like to use a session
variable when defining the Select Command for a gridview but it doesnt
seem to like it (see code sample below). Does anyone have any
suggestions?
<asp:SqlDataSource
ID="SqlDataSource1"
runat="server"
ConnectionString="<%$
ConnectionStrings
rogressConnectionString %>"
SelectCommand= "SELECT [SONo], [SOContact], [SOCustOrder],
[SODate], [SOContractNo], [SOSalesRep] FROM [SalesOrder] WHERE
[SOCustID ] = '" & Session("myAccount") & "' ORDER BY [SONo],
[SODate];">
</asp:SqlDataSource>
Previously before I had populated the grid on the page load which
worked but this wouldnt allow me to allow paging and sorting on the
grid (see below)
<%@ Page Language="VB" MasterPageFile="~/Progress.master"
Title="Untitled Page" %>
<script runat="server">
Dim strConn As String =
ConfigurationManager.ConnectionStrings("ProgressConnectionString").ConnectionString
Dim myReader As SqlDataReader
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)
Using con As New SqlConnection(strConn)
con.Open()
Dim strSQL As String = "SELECT [SONo], [SOContact],
[SOCustOrder], " _
& "[SODate], [SOContractNo], [SOSalesRep] " _
& "FROM [SalesOrder] " _
& "WHERE [SOCustID ] = '" & CStr(Session("myAccount"))
& "' " _
& "ORDER BY [SONo], [SODate];"
' Create command
Dim myCommand As New SqlCommand(strSQL, con)
myReader = myCommand.ExecuteReader()
If myReader.HasRows Then
Me.CustomerOrdersGrid.DataSource = myReader
Me.CustomerOrdersGrid.DataBind()
End If
End Using
End Sub
</script>
Many thanks in advance
Paul
variable when defining the Select Command for a gridview but it doesnt
seem to like it (see code sample below). Does anyone have any
suggestions?
<asp:SqlDataSource
ID="SqlDataSource1"
runat="server"
ConnectionString="<%$
ConnectionStrings
SelectCommand= "SELECT [SONo], [SOContact], [SOCustOrder],
[SODate], [SOContractNo], [SOSalesRep] FROM [SalesOrder] WHERE
[SOCustID ] = '" & Session("myAccount") & "' ORDER BY [SONo],
[SODate];">
</asp:SqlDataSource>
Previously before I had populated the grid on the page load which
worked but this wouldnt allow me to allow paging and sorting on the
grid (see below)
<%@ Page Language="VB" MasterPageFile="~/Progress.master"
Title="Untitled Page" %>
<script runat="server">
Dim strConn As String =
ConfigurationManager.ConnectionStrings("ProgressConnectionString").ConnectionString
Dim myReader As SqlDataReader
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)
Using con As New SqlConnection(strConn)
con.Open()
Dim strSQL As String = "SELECT [SONo], [SOContact],
[SOCustOrder], " _
& "[SODate], [SOContractNo], [SOSalesRep] " _
& "FROM [SalesOrder] " _
& "WHERE [SOCustID ] = '" & CStr(Session("myAccount"))
& "' " _
& "ORDER BY [SONo], [SODate];"
' Create command
Dim myCommand As New SqlCommand(strSQL, con)
myReader = myCommand.ExecuteReader()
If myReader.HasRows Then
Me.CustomerOrdersGrid.DataSource = myReader
Me.CustomerOrdersGrid.DataBind()
End If
End Using
End Sub
</script>
Many thanks in advance
Paul