J
Jeff
Hi -
I'm having trouble Databinding a SQLDataReader to a DataGrid control.
I have an ASP.NET web page accessing a SQL database. I've used VS to build
the app and stored it in a directory of my localhost on my development
machine. The database is on the web.
When I run the app on the local machine, IE opens, loads my aspx page from
localhost, and hangs. (Eventually I get a page cannot be displayed error.)
No exceptions are raised.
In the aspx page, I dragged a datagrid from the toolbox to the page and
named it "dgCustomers".
In the aspx.vb page, I define the reader as follows:
Dim conMain As SqlConnection
Dim sqlCmd As SqlCommand
Dim strConn As String
Dim strSQL As String
strConn = [my connection string]
conMain = New SqlConnection(strConn)
sqlCmd = New SqlCommand("SELECT FirstName, LastName FROM
eNPCustomers", conMain)
conMain.Open()
Dim rdrCustomers As SqlDataReader = sqlCmd.ExecuteReader
I bind it to the datagrid as follows:
dgCustomers.DataSource = rdrCustomers
dgCustomers.DataBind()
The page hangs, again when I run it on my development machine. (It runs
fine if I change the page directive from codebehind to src and upload it to
my 3rd-party web server.)
If, instead of the last 2 databinding lines, I simply print out the reader
rows, the page runs fine (all data is displayed as expected):
While rdrCustomers.Read
Response.Write("<br>" & rdrCustomers.GetString(0) & " " &
rdrCustomers.GetString(1))
End While
So the reader seems to successfully get the data from the sql database.
Just to see whether there is something amiss with databinding, I tried the
following (instead of the datareader) and it works fine:
Dim arrCustomers() As String = {"tom", "dick", "harry"}
dgCustomers.DataSource = arrCustomers
dgCustomers.DataBind()
What am I doing wrong??
Thanks for your help.
- Jeff
I'm having trouble Databinding a SQLDataReader to a DataGrid control.
I have an ASP.NET web page accessing a SQL database. I've used VS to build
the app and stored it in a directory of my localhost on my development
machine. The database is on the web.
When I run the app on the local machine, IE opens, loads my aspx page from
localhost, and hangs. (Eventually I get a page cannot be displayed error.)
No exceptions are raised.
In the aspx page, I dragged a datagrid from the toolbox to the page and
named it "dgCustomers".
In the aspx.vb page, I define the reader as follows:
Dim conMain As SqlConnection
Dim sqlCmd As SqlCommand
Dim strConn As String
Dim strSQL As String
strConn = [my connection string]
conMain = New SqlConnection(strConn)
sqlCmd = New SqlCommand("SELECT FirstName, LastName FROM
eNPCustomers", conMain)
conMain.Open()
Dim rdrCustomers As SqlDataReader = sqlCmd.ExecuteReader
I bind it to the datagrid as follows:
dgCustomers.DataSource = rdrCustomers
dgCustomers.DataBind()
The page hangs, again when I run it on my development machine. (It runs
fine if I change the page directive from codebehind to src and upload it to
my 3rd-party web server.)
If, instead of the last 2 databinding lines, I simply print out the reader
rows, the page runs fine (all data is displayed as expected):
While rdrCustomers.Read
Response.Write("<br>" & rdrCustomers.GetString(0) & " " &
rdrCustomers.GetString(1))
End While
So the reader seems to successfully get the data from the sql database.
Just to see whether there is something amiss with databinding, I tried the
following (instead of the datareader) and it works fine:
Dim arrCustomers() As String = {"tom", "dick", "harry"}
dgCustomers.DataSource = arrCustomers
dgCustomers.DataBind()
What am I doing wrong??
Thanks for your help.
- Jeff