Click here to Skip to main content
Rate this: bad
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
            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)

            End If
Posted 16-Nov-12 20:22pm
Edited 16-Nov-12 20:40pm
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 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
nityasri at 17-Nov-12 2:36am
@original griff...we are using it in a mobile web application...

1 solution

Rate this: bad
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.
nityasri at 18-Nov-12 10:40am

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 8,478
1 OriginalGriff 6,516
2 Peter Leow 3,567
3 Zoltán Zörgő 3,386
4 Richard MacCutchan 2,397

Advertise | Privacy | Mobile
Web04 | 2.8.150123.1 | Last Updated 17 Nov 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100