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?
Last edited by WizBang; January 20th, 2011 at 11:49 AM.
Reason: Added [code] tags
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.