Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
error : object reference not set to an instance of an object...can anyone help me .thanks in advance
 


           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 16-Nov-12 19:22pm
Edited 16-Nov-12 19:40pm
ridoy50.5K
v2
Comments
Krunal R at 17-Nov-12 2:02am
   
for which object you are getting such error (i.e DataAdapter or Datset) ?
nityasri at 17-Nov-12 2:23am
   
@krunal....in dataset i am getting error...
OriginalGriff at 17-Nov-12 2:31am
   
Which line is the error occurring on?
nityasri at 17-Nov-12 2:34am
   
DropDownList1.Items.Add(ds.Tables(0).Rows(i).Item(0))
nityasri at 17-Nov-12 2:36am
   
@original griff...we are using it in a mobile web application...

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Comments
nityasri at 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
Your Filters
Interested
Ignored
     
0 Shai Vashdi 1,838
1 OriginalGriff 313
2 Tadit Dash 300
3 Sergey Alexandrovich Kryukov 250
4 Peter Leow 220
0 Sergey Alexandrovich Kryukov 9,440
1 OriginalGriff 5,618
2 Peter Leow 4,280
3 Maciej Los 3,540
4 Abhinav S 3,363


Advertise | Privacy | Mobile
Web02 | 2.8.140415.2 | Last Updated 17 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid