Click here to Skip to main content
12,296,731 members (62,738 online)
Rate this:
Please Sign up or sign in to vote.
See more: VB 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 19:22pm
Edited 16-Nov-12 19:40pm
Krunal R 17-Nov-12 2:02am
for which object you are getting such error (i.e DataAdapter or Datset) ?
nityasri 17-Nov-12 2:23am dataset i am getting error...
OriginalGriff 17-Nov-12 2:31am
Which line is the error occurring on?
nityasri 17-Nov-12 2:34am
nityasri 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 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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.160525.2 | Last Updated 17 Nov 2012
Copyright © CodeProject, 1999-2016
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