Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: Dataset question


Message #1 by "Greg Quinn" <greg@i...> on Fri, 11 Oct 2002 13:56:12 -0700
I have the following code that basically checks if the datareader is empty,
if not, it binds the records in the datareader to my dropdownlist.

Problem is, if there is only one record in the db I get the error ' Object
reference not set to an instance of an object'

What am I doing wrong here?

			Dim objDataReader as SqlDataReader
			objDataReader = objCommand.ExecuteReader()

			if objDataReader.Read = False Then
				selProfileList.Items.Insert(0, new ListItem("No Profiles Found", 0))
			Else
				selProfileList.DataSource = objDataReader
				selProfileList.DataBind()
			End If

Message #2 by "Carole D. Sullivan" <carolesullivan@e...> on Tue, 15 Oct 2002 18:43:26
> I have the following code that basically checks if the datareader is 
empty,
if not, it binds the records in the datareader to my dropdownlist.

Problem is, if there is only one record in the db I get the error ' Object
reference not set to an instance of an object'

What am I doing wrong here?

			Dim objDataReader as SqlDataReader
			objDataReader = objCommand.ExecuteReader()

			if objDataReader.Read = False Then
				selProfileList.Items.Insert(0, new 
ListItem("No Profiles Found", 0))
			Else
				selProfileList.DataSource = objDataReader
				selProfileList.DataBind()
			End If

Message #3 by "Carole D. Sullivan" <carolesullivan@e...> on Tue, 15 Oct 2002 18:58:05
Whoops, I think I just posted a blank reply.  You refer to this a 
a 'dataset' question...but datasets are generated from data adaptors, not 
datareaders, I am not sure you can USE a data reader as a data source for
a databound control.

I assume you did not Dim your datareader inside another IF statement?
Have you populated a databound control from a data reader before?

I did use a data reader to manually add items to a list:
-----------------------------
Dim orgReader As SqlDataReader
        objCmd.Connection = conCDB
        Try
            'open connection and execute reader
            conCDB.Open()
            orgReader = objCmd.ExecuteReader()
            'add items to drop down list
            Do While orgReader.Read
                ddlOrgs.Items.Add(New ListItem(orgReader("ORGNAME"), 
orgReader("ORGID")))
            Loop
        Finally
            orgReader.Close()
            conCDB.Close()
        End Try




> > I have the following code that basically checks if the datareader is 
e> mpty,
i> f not, it binds the records in the datareader to my dropdownlist.

> Problem is, if there is only one record in the db I get the error ' 
Object
r> eference not set to an instance of an object'

> What am I doing wrong here?

> 			Dim objDataReader as SqlDataReader
	> 		objDataReader = objCommand.ExecuteReader()

> 			if objDataReader.Read = False Then
	> 			selProfileList.Items.Insert(0, new 
L> istItem("No Profiles Found", 0))
	> 		Else
	> 			selProfileList.DataSource = objDataReader
	> 			selProfileList.DataBind()
	> 		End If


  Return to Index