Click here to Skip to main content
15,892,161 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
error : object reference not set to an instance of an object...can anyone help me .thanks in advance



VB
Dim da As New SqlClient.SqlDataAdapter("select job_no from offsale.jobdetails (nolock) where location='" & Session("frmlogin_var_area") & "'", mycon)

 Dim ds As New DataSet

 da.Fill(ds)

 mycon1.Close()
 da.Dispose()
 'jobno.Items.Add("Select")
 If ds.Tables(0).Rows.Count > 0 Then
     'txtjobno1.Text = ds.Tables(0).Rows(0).Item(0) & " "
     For i = 0 To (ds.Tables(0).Rows.Count - 1)
         'jobno.Items.Add(ds.Tables(0).Rows(i).Item(0))

         DropDownList1.Items.Add(ds.Tables(0).Rows(i).Item(0))

     Next
 End If
 ds.Dispose()
Posted
Updated 16-Nov-12 19:40pm
v2
Comments
[no name] 17-Nov-12 2:02am    
for which object you are getting such error (i.e DataAdapter or Datset) ?
nityasri 17-Nov-12 2:23am    
@krunal....in dataset i am getting error...
OriginalGriff 17-Nov-12 2:31am    
Which line is the error occurring on?
nityasri 17-Nov-12 2:34am    
DropDownList1.Items.Add(ds.Tables(0).Rows(i).Item(0))
nityasri 17-Nov-12 2:36am    
@original griff...we are using it in a mobile web application...

1 solution

Your code is assuming that the DataSet you created and Filled has tables and rows in it.

Either your DataSet doesn't have tables and Table(0) is returning null (Nothing in VB.NET) or the table does exist and Rows(i) is returning null, or Rows(i) is returning a row with no columns.

Only you can figure out which by using the debugger to inspect that line of code when the exception is thrown.
 
Share this answer
 
Comments
nityasri 18-Nov-12 10:40am    
ok..thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900