assemly error,indexoutofrange error at vb.net
VB.NET & MS Access Issue
I have created a database in ms access2000,and at at vb.Net I hv created search,insert,update,del buttons.
Problems are listed bellow:
1:index out of range-"when I search at input box"
2:after running 2 times the program error shows"could not load file or assembly'program name'.Exception from HR0x80131407,
Codes are given bellow
Imports System
Imports System.Data
Imports System.Data.OleDb
Public Class Form1
Dim cnnOLEDB As New OleDbConnection
Dim cmdOLEDB As New OleDbCommand
Dim cmdInsert As New OleDbCommand
Dim cmdUpdate As New OleDbCommand
Dim cmdDelete As New OleDbCommand
Dim strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=I:\Documents and Settings\rony\My Documents\TestDB.Mdb;"
Private Sub Form1_Load(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles MyBase.Load
Try
cnnOLEDB.ConnectionString = strConnectionString
Catch ext As OleDbException
MsgBox(ext.Message, MsgBoxStyle.Critical, "OLEDB Error")
cnnOLEDB.Open()
End Try
End Sub
Private Sub btnSearch_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles btnSearch.Click
txtAearchResult.Text = ""
Dim vSearch As String = InputBox("Enter Integer number to search name:")
If vSearch <> "" Then
cmdOLEDB.CommandText = "SELECT ID FROM Authors WHERE ID=" & CInt(vSearch)
cmdOLEDB.Connection = cnnOLEDB
Dim rdrOLEDB As OleDbDataReader = cmdOLEDB.ExecuteReader()
If rdrOLEDB.Read = True Then
txtAearchResult.Text &= rdrOLEDB.Item(0).ToString & " " & _
rdrOLEDB.Item(1).ToString()
rdrOLEDB.Close()
Exit Sub
Else
MsgBox("Record not found")
Exit Sub
End If
Else
MsgBox("Enter search value.")
Exit Sub
End If
End Sub
Private Sub btnInsert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInsert.Click
If txtID.Text <> "" And txtAuthor.Text <> "" Then
cmdInsert.CommandText = "INSERT INTO Authors (ID, Author) VALUES ('" & txtID.Text & "', '" & txtAuthor.Text & "');"
'MsgBox(cmdInsert.CommandText)
cmdInsert.CommandType = CommandType.Text
cmdInsert.Connection = cnnOLEDB
'create con obj
cnnOLEDB.ConnectionString = strConnectionString
'''''''''
cnnOLEDB.Open()
cmdInsert.ExecuteNonQuery()
MsgBox(txtID.Text = "Record inserted.")
txtAuthor.Text = ""
'cnnOLEDB.Open()
Else
MsgBox("Enter the required values:" & _
vbNewLine & "1. ID" & vbNewLine & "2.Author")
End If
cnnOLEDB.Close()
cmdInsert.Dispose()
cnnOLEDB.Dispose()
End Sub
Private Sub btnUpdate_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles btnUpdate.Click
If txtID.Text <> "" And txtAuthor.Text <> "" Then
cmdUpdate.CommandText = "UPDATE Authors SET Author = '" & txtAuthor.Text & "'WHERE ID = " & txtID.Text & ";"
'MsgBox(cmdUpdate.CommandText)
cmdUpdate.CommandType = CommandType.Text
cmdUpdate.Connection = cnnOLEDB
'''''''''
cnnOLEDB.Open()
cmdUpdate.ExecuteNonQuery()
MsgBox(txtID.Text = "Record updated.")
txtAuthor.Text = ""
Else
MsgBox("Enter the required values:" & vbNewLine & "1. ID" & vbNewLine & "2.Author")
End If
cnnOLEDB.Close()
cmdUpdate.Dispose()
cnnOLEDB.Dispose()
End Sub
Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
If txtID.Text <> "" Then
cmdDelete.CommandText = "DELETE FROM Authors WHERE ID = " & _
txtID.Text & ";"
'MsgBox(cmdDelete.CommandText)
cmdDelete.CommandType = CommandType.Text
cmdDelete.Connection = cnnOLEDB
'''''''''
cnnOLEDB.Open()
cmdDelete.ExecuteNonQuery()
MsgBox(txtID.Text = "Record deleted.")
txtAuthor.Text = ""
cmdDelete.Dispose()
Else
MsgBox("Enter the required values:" & vbNewLine & "1. ID")
End If
cnnOLEDB.Close()
cmdUpdate.Dispose()
cnnOLEDB.Dispose()
End Sub
End Class
-reply by tarique
Reply