CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Threaded View

  1. #1
    Join Date
    Jan 2011
    Posts
    1

    Update data into database

    My Code:
    Code:
    Imports System.Data
    Public Class Form4
        Dim dt As New DataTable()
        Dim rowIndex As Integer = 0
        Dim connstr As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=Library_System.mdb"
        Dim sqlStr As String = "SELECT * FROM Book_Issue_Details"
        Dim dataAdapter As New OleDb.OleDbDataAdapter(sqlStr, connstr)
        Dim issueID As Integer
    
    
        Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click
    
            txtDateIssue.Clear()
            txtISBN.Clear()
            txtSID.Clear()
    
        End Sub
    
        Private Sub btnBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBack.Click
    
            Form2.Show()
    
            Me.Close()
    
        End Sub
    
        Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
            End
        End Sub
    
        Private Sub btnDone_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDone.Click
    
            Dim dataAdapter As New OleDb.OleDbDataAdapter(sqlStr, connstr)
            Dim commandBuilder As New OleDb.OleDbCommandBuilder(dataAdapter)
            Dim dsNewRow As DataRow
            dsNewRow = dt.NewRow()
    
            dsNewRow.Item("Book_ISBN") = txtISBN.Text
            dsNewRow.Item("Date_Issued") = DateString
            dsNewRow.Item("Book_Issued_To") = txtSID.Text
            dt.Rows.Add(dsNewRow)
            dataAdapter.Update(dt)
            rowIndex = dt.Rows.Count - 0
            issueID = dt.Rows(rowIndex)("Issue_ID") + 1
            txtISBN.Text = issueID
    
            MsgBox("Book Issued Successfully")
            Form2.Show()
            Me.Hide()
    
        End Sub
    
        Private Sub Form4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim dataAdapter As New OleDb.OleDbDataAdapter(sqlStr, connstr)
            dataAdapter.Fill(dt)
            dataAdapter.Dispose()
    
        End Sub
    End Class
    My problem is the form is loading and when I type in the data and want to update my database. It says 'System.IndexOutOfRangeException was unhandled'. Anyone help me with this? Where do I have problem in the code?
    Attached Images Attached Images
    Last edited by WizBang; January 20th, 2011 at 11:49 AM. Reason: Added [code] tags

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

Featured