473,387 Members | 1,621 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

SQL Error on my dataset Last row

Hi,



This is the first time I am running through a dataset the way I am doing it now and I have specific reasons for doing it this way. I am having a issue when I get to the last row of my dataset and was wondering if someone could help my and let me know what I am doing wrong.

My error says there is no row after the last row, wich is true, but what do I need to do to correct that?

Here is my code:

Expand|Select|Wrap|Line Numbers
  1. Dim ds As New DataSet()
  2.     Dim rpos As Integer
  3.  
  4.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  5.  
  6.  
  7. Dim con As New SqlClient.SqlConnection
  8.         con.ConnectionString = [properties goes here]
  9.  
  10.         con.Open()
  11.         Try
  12.             If con.State = 1 Then
  13.                 MsgBox("Connection Succesful!!")
  14.             End If
  15.         Catch ex As SqlClient.SqlException
  16.             MessageBox.Show(ex.Message, "Connection Error!")
  17.         End Try
  18.  
  19.         Dim com As New SqlClient.SqlCommand
  20.         com.Connection = con
  21.         com.CommandText = "Select * from Customer Where Number = '" & TextBox3.Text & "'"
  22.  
  23.         Dim da As New SqlClient.SqlDataAdapter
  24.  
  25.         Try
  26.             da.SelectCommand = com
  27.             da.Fill(ds, "Number")
  28.             rpos = 0
  29.  
  30.             TextBox1.Text = ds.Tables("Number").Rows(rpos)("CKNumber").ToString
  31.             TextBox2.Text = ds.Tables("Number").Rows(rpos)("CustName").ToString
  32.  
  33.         Catch ex As SQLClient.SQLException
  34.             MsgBox(ex.Message)
  35.         End Try
  36.  
  37.     End Sub
  38.  
  39.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  40.         rpos += 1
  41.         Navigate()
  42.     End Sub
  43.  
  44.  
  45.     Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
  46.         rpos -= 1
  47.         Navigate()
  48.     End Sub
  49.     Private Sub Navigate()
  50.         TextBox1.Text = ds.Tables("Number").Rows(rpos)("CKNumber").ToString
  51.             TextBox2.Text = ds.Tables("Number").Rows(rpos)("CustName").ToString
  52.     End Sub
Feb 21 '07 #1
4 1124
Hi,

Put the conditional statement before accessing the row record.

e.g.

if not ds is nothing
if ds.tables.count > 0
if ds.tables(0).rows.count > 0
' insert your statement which will access the row record
end if
end if
end if

Harold
Feb 21 '07 #2
OK,

This is what I did and it Still is giving me that error. That means that this is wrong as well?



If Not ds Is Nothing Then
If ds.Tables.Count > 0 Then
If ds.Tables(0).Rows.Count > 0 Then
TextBox1.Text = ds.Tables("Number").Rows(rpos)("CKNumber").ToStrin g
End If
End If
End If
Feb 21 '07 #3
kenobewan
4,871 Expert 4TB
What line and error numbers do you get?
Feb 22 '07 #4
When I get to the last record it still gives me an error saying: There is no record 9. Wich means I have 8 records starting at 0, but when I get to record 9 there is nothing and that breaks my program with the error noted above.
Feb 22 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: dtblankenship | last post by:
Hello everyone, I know this question has been asked many times in the forums, and after spending a few days reading, I am still confused as to the answer. I have a ListBox (lstBox),...
6
by: Mikey G | last post by:
Hi, Here is a shorter code example since the last message I posted got truncated. So the problem is I created a simple VB.NET 2003 application through Visual Studio that connects to a MySQL...
5
by: Bronislav | last post by:
I have an error when I try to delete last record in the record set. The code I'm using is: lcurrow = Me.BindingContext(DsTextProdMain, "TextProductsMain").Current lcurrow.Delete() This code...
2
by: Michael | last post by:
Hi Everyone, Please help me on this one. I have the following function: Public Sub SearchFor(ByRef mType As Module1.SearchForType, ByRef mValue As String) On Error GoTo Err_Handler Dim Proc As...
7
by: Alan Pretre | last post by:
I have an application installed at a customer site that has been getting a general network error for a couple of years. I was hoping that .NET 2.0 would clear it up, but unfortunately it didn't. ...
2
by: Peter Van Wilrijk | last post by:
Hi, In VB6 I used a method requery to repopulate a recordset. I don't find an equivalent for the .NET dataset. I don't update my datasets at all, but I use them to navigate through subsets...
0
by: BVA3105 | last post by:
i update a database with a dataset and a SqlAdapter with success but when i clear and refill my dataset i always retreive the old values. I have to wait for 5 seconds to get the corrects values. ...
17
by: =?Utf-8?B?SGVyYg==?= | last post by:
I have created a report and subreport in VB/ASP.NET. The report works fine but the subreport will not display. The subreport, when displayed as a standalone report, works fine. Any help I can...
6
by: marylipscomb | last post by:
I am using VB.NET. I am trying to connect a button so that when it is clicked the gridview pops up the data. Partial Class Switchboard Inherits System.Web.UI.Page Protected Sub...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.