Results 1 to 4 of 4

Thread: There is no row at position 0. VB 2008

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2004
    Posts
    53

    There is no row at position 0. VB 2008

    Having a problem with program saying there is nothing at row 0. I know there is but it says there is not. I am using SQL Server compact 3.5 sp1. I am following the HomeAndLearn Tutorial for access, so maybe the problem is that it is using access and I am using SQL Server CE?

    Uploaded image of error

    Code:
    Public Class Form1
    
        Private Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoad.Click
            Dim con As New OleDb.OleDbConnection
            Dim ds As New DataSet
            Dim da As OleDb.OleDbDataAdapter
            Dim sql As String
            con.ConnectionString = "Provider=Microsoft.SQLSERVER.CE.OLEDB.3.5;Data Source=|DataDirectory|\addressdb.sdf;"
    
            con.Open()
            MsgBox("A Connection to the Database is now open")
    
            sql = "SELECT * FROM AddressBookT"
            da = New OleDb.OleDbDataAdapter(sql, con)
            da.Fill(ds, "AddressBook")
    
            con.Close()
            MsgBox("The Connection to the Database is now Closed")
    
            txtFirstName.Text = ds.Tables("AddressBook").Rows(0).Item(1)
    
        End Sub
    Attached Images Attached Images  
    To save on queries thank you for your help if you helped me.

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: There is no row at position 0. VB 2008

    Are you sure that line isn't supposed to be before the con.Close()?

  3. #3

    Thread Starter
    Member
    Join Date
    Sep 2004
    Posts
    53

    Re: There is no row at position 0. VB 2008

    Ok I found problem, I did not have any data entered so naturally it would not display nothing because nothing was there to display.
    To save on queries thank you for your help if you helped me.

  4. #4

    Thread Starter
    Member
    Join Date
    Sep 2004
    Posts
    53

    Re: There is no row at position 0. VB 2008

    OK, so this will not solve the problem, I am receiving this error on some of the buttons but not all. The code below represents a working and non working button

    Working Button
    Code:
    Private Sub KryptonButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNextContact.Click
            If inc <> maxrows - 1 Then
                inc = inc + 1
                NavigateRecords()
            ElseIf inc = -1 Then
                MsgBox("No Contacts In The Database Yet")
            ElseIf inc = 0 Then
                MsgBox("You Are At The First Contact")
            End If
    
        End Sub
    Non Working Button
    Code:
        Private Sub btnFirstContact_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFirstContact.Click
            If inc <> 0 Then
                inc = 0
                NavigateRecords()
            ElseIf inc = 0 Then
                MsgBox("No Contacts In The Database Yet")
            End If
        End Sub
    All Of The Code
    Code:
    Imports System.Data
    
    Public Class Form1
        Dim inc As Integer
        Dim maxrows As Integer
        Dim con As New OleDb.OleDbConnection
        Dim ds As New DataSet
        Dim da As OleDb.OleDbDataAdapter
        Dim sql As String
    
    
        Private Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    
    
        End Sub
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            databaseConnect()
            btnSaveContact.Enabled = False
    
        End Sub
        Private Sub databaseConnect()
            con.ConnectionString = "Provider=Microsoft.SQLSERVER.CE.OLEDB.3.5;Data Source=|DataDirectory|\addressdb.sdf;"
    
            sql = "SELECT * FROM AddressBookT"
            da = New OleDb.OleDbDataAdapter(sql, con)
            da.Fill(ds, "AddressBook")
    
            maxrows = ds.Tables("AddressBook").Rows.Count
            inc = -1
    
        End Sub
        Private Sub KryptonButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNextContact.Click
            If inc <> maxrows - 1 Then
                inc = inc + 1
                NavigateRecords()
            ElseIf inc = -1 Then
                MsgBox("No Contacts In The Database Yet")
            ElseIf inc = 0 Then
                MsgBox("You Are At The First Contact")
            End If
    
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    
        End Sub
    
        Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
            Me.Close()
    
        End Sub
    
        Private Sub btnPreviousContact_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPreviousContact.Click
            If inc > 0 Then
                inc = inc - 1
                NavigateRecords()
            ElseIf inc = -1 Then
                MsgBox("No Contacts In The Database Yet")
            ElseIf inc = 0 Then
                MsgBox("You Are At The First Contact")
    
            End If
        End Sub
    
        Private Sub btnLastContact_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLastContact.Click
            If inc <> maxrows - 1 Then
                inc = maxrows - 1
                NavigateRecords()
            ElseIf inc = -1 Then
                MsgBox("No Contacts In The Database Yet")
            ElseIf inc = 0 Then
                MsgBox("You Are At The Last Contact")
            End If
        End Sub
    
        Private Sub btnFirstContact_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFirstContact.Click
            If inc <> 0 Then
                inc = 0
                NavigateRecords()
            ElseIf inc = 0 Then
                MsgBox("No Contacts In The Database Yet")
            End If
        End Sub
    
        Private Sub btnUpdateContact_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdateContact.Click
            UpdateData()
    
            MsgBox("Data updated")
        End Sub
    
        Private Sub btnNewContact_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNewContact.Click
            btnSaveContact.Enabled = True
            btnNewContact.Enabled = False
            btnUpdateContact.Enabled = False
            btnDeleteContact.Enabled = False
    
            txtFirstName.Clear()
            txtLastName.Clear()
            txtStreet.Clear()
            txtCity.Clear()
            txtState.Clear()
            txtZip.Clear()
            txtHomePhone.Clear()
            txtCellPhone.Clear()
    
        End Sub
    
        Private Sub btnSaveContact_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSaveContact.Click
    
    
        End Sub
        Private Sub UpdateData()
            Dim cb As New OleDb.OleDbCommandBuilder(da)
    
            ds.Tables("AddressBook").Rows(inc).Item(2) = txtFirstName.Text
            ds.Tables("AddressBook").Rows(inc).Item(1) = txtLastName.Text
            ds.Tables("AddressBook").Rows(inc).Item(3) = txtStreet.Text
            ds.Tables("AddressBook").Rows(inc).Item(4) = txtCity.Text
            ds.Tables("AddressBook").Rows(inc).Item(5) = txtState.Text
            ds.Tables("AddressBook").Rows(inc).Item(6) = txtZip.Text
            ds.Tables("AddressBook").Rows(inc).Item(7) = txtHomePhone.Text
            ds.Tables("AddressBook").Rows(inc).Item(8) = txtCellPhone.Text
    
            da.Update(ds, "AddressBook")
        End Sub
        Private Sub NavigateRecords()
    
            txtFirstName.Text = ds.Tables("AddressBook").Rows(inc).Item(2)
            txtLastName.Text = ds.Tables("AddressBook").Rows(inc).Item(1)
            txtStreet.Text = ds.Tables("AddressBook").Rows(inc).Item(3)
            txtCity.Text = ds.Tables("AddressBook").Rows(inc).Item(4)
            txtState.Text = ds.Tables("AddressBook").Rows(inc).Item(5)
            txtZip.Text = ds.Tables("AddressBook").Rows(inc).Item(6)
            txtHomePhone.Text = ds.Tables("AddressBook").Rows(inc).Item(7)
            txtCellPhone.Text = ds.Tables("AddressBook").Rows(inc).Item(8)
    
        End Sub
    
        Private Sub btnCancelChanges_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancelChanges.Click
            btnSaveContact.Enabled = False
            btnNewContact.Enabled = True
            btnUpdateContact.Enabled = True
            btnDeleteContact.Enabled = True
    
            inc = 0
            NavigateRecords()
    
    
        End Sub
    End Class
    To save on queries thank you for your help if you helped me.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width