|
Subject:
|
datareader/datagrid will not work
|
|
Posted By:
|
eon
|
Post Date:
|
1/28/2004 4:58:15 AM
|
I'm having so much trouble I've been trying to solve the following problem for hours and hours. what I'm trying to do is output an grid from a table, i'm using code behind and outputting to an <asp:datagrid>, or trying to, I had some severe problem with trying to make a login searching for username/password and couldn't output the userID but I solved it. somehow I think the problems are related, anyway, here's the code
Dim dgrSongLog As DataGrid Dim strConnection As String = Application("strconnection") Dim objConnection As New SqlConnection(strConnection) objConnection.Open() Dim strProcName = "SELECT * FROM tblSongLog WHERE uid ='" & Request.QueryString("uid") & "' ORDER BY inserted DESC" Dim objCommand As New SqlCommand(strProcName, objConnection) Dim objReader As SqlDataReader = objCommand.ExecuteReader()
dgrSongLog.DataSource = objReader dgrSongLog.DataBind()
AND HERE'S THE ERROR MESSAGE
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 54: Dim objReader As SqlDataReader = objCommand.ExecuteReader() Line 55: Line 56: dgrSongLog.DataSource = objReader Line 57: dgrSongLog.DataBind() Line 58:
it doesn't seem the matter if I'm trying with oledb or sql, datagrid och datareader, it just won't budge on the instansiating. I'm pulling my hair here.
Sincerely Bennie
|
|
Reply By:
|
bmains
|
Reply Date:
|
1/28/2004 8:52:47 AM
|
Hello,
Maybe as an alternative, use a SQLDataAdapter and pass the data into a data set. If you still get an error, then it may be either the uid is not coming back to the query, or something else... What is your connection string, and how does the user log into the system? Is the querystring value coming back, or is it blank?
Brian
|
|
Reply By:
|
planoie
|
Reply Date:
|
1/28/2004 10:30:31 AM
|
Dim dgrSongLog As DataGrid
The datagrid hasn't been instantiated.
Why are you dimming a datagrid there? The datagrid should already exist as a variable within the page class. Are you using codebehind or inline code?
|