Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Object reference not set to an instance of an object error

Status
Not open for further replies.

richfield

IS-IT--Management
Jan 6, 2005
23
GB
Hi I keep getting the following error and cant seem to figure it out;

Object reference not set to an instance of an object.

below is the code block which it finds the error;

Dim dst as DataSet
Dim dad as sqlDataAdapter
Dim strSql as string



Sub LoadDetails()
dst = new dataset
strSql= strSql.format("select Sales from tblSales where SalesID={0}",radioSales.selecteditem.value)

conn = new sqlConnection(strConn)
dad = new sqldataadapter(strSql,conn)
dad.fill(dst,"tblSales")
txtSales.text = dst.tables(0).rows(0).item(0)
datagrid2.datasource=dst
datagrid2.databind()

conn.close()

End Sub

Any help would be appreciated.

Cheers
Rich
 
Have you stepped through the code? If so, which line does it error on? This will tell which object deosn't exist.

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
richfield,

My guess would be that you need to specify the table in the datasource definition like so:

Datagrid2.Datasource = dst.Tables("tblSales")

I don't think a grid can bind to a dataset, I think it needs to bind to a table contained in the dataset.

Cesar
 
i don't see where conn is declared...does the error show the line where it occurs?
 
The error occurs on this line


strSql= strSql.format("select Sales from tblSales where SalesID={0}",radioSales.selecteditem.value)


I've tried

textbox1.text = radioSales.selecteditem.value

to try and debug and it gives me the same error message, even though radioSales has a value
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top