have a problem on my code it runs and display what I want but has a error says
ArgumentOutOfRangeException was unhandled
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
it pointing on MsgBox(dta(0)(1).ToString)
this is my code
ArgumentOutOfRangeException was unhandled
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
it pointing on MsgBox(dta(0)(1).ToString)
this is my code
VB.NET:
Public Class dbConnection
Private dbProvider As String
Private dbSource As String
Private dbPassword As String
Private dbName As String
Private dbHost As String
Private count As Integer
Private con As New OleDb.OleDbConnection
Private comm As New OleDb.OleDbCommand
Private da As New OleDb.OleDbDataAdapter
Private ds As New DataSet
Private Sub dbGetConnection()
dbName = "dbSAIS.mdb"
dbHost = ""
dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
dbSource = "Data Source = " & dbName & ";"
dbPassword = "Jet OLEDB:Database Password=password;"
con.ConnectionString = dbProvider & dbSource & dbPassword
End Sub
Function dbConnect() As Integer
Dim status As Boolean = 2
dbGetConnection()
Try
con.Open()
Catch ex As Exception
status = 0
End Try
If status <> 0 Or status <> 2 Then
status = 1
End If
Return status
End Function
Function dbClose() As Integer
Dim status As Boolean = 2
Try
con.Close()
Catch ex As Exception
status = 0
End Try
If status <> 0 Or status <> 2 Then
status = 1
End If
Return status
End Function
Function executeNonQuery(ByVal query As String) As Integer
Dim status As Boolean
comm.CommandText = query
comm.Connection = con
dbConnect()
Try
comm.ExecuteNonQuery()
Catch ex As Exception
End Try
dbClose()
Return status
End Function
Public Function executeQuery(ByVal query As String) As ArrayList
Dim dtArray As New ArrayList
dbConnect()
Try
da.SelectCommand = New OleDb.OleDbCommand(query, con)
da.Fill(ds, "Table")
count = ds.Tables("Table").Rows.Count
For Each row As DataRow In ds.Tables("Table").Rows
dtArray.Add(CType(row, DataRow))
Next
Catch ex As Exception
End Try
dbClose()
Dim dta As New ArrayList
dta = dtArray
MsgBox(dta(0)(1).ToString)
Return dtArray
End Function
Function dbCount() As Integer
Return Count
End Function
End Class