Ok I am writing a inventory program. I am using ms access and I keep getting an error that I think it is telling me that the second column I am trying to read for the table it thinks it should be integer and I need it to be a string. Here is the problem code.
Dim loc As String
loc = System.Environment.CurrentDirectory
loc = Microsoft.VisualBasic.Left(loc, loc.Length - 3)
Dim sConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + loc + "Inventory.mdb"
Dim Conn As New OleDb.OleDbConnection(sConnString)
Dim tab As String
tab = Me.Text
tab = Microsoft.VisualBasic.Right(tab, tab.Length - 20)
tab = tab.Replace(" ", "_")
Try
Dim sCommand As String = "Select * From " + tab
Conn.Open()
Dim Command As New OleDb.OleDbCommand(sCommand, Conn)
Dim reader As OleDb.OleDbDataReader
reader = Command.ExecuteReader
data = reader.GetSchemaTable
Dim ro As DataRow
Do While reader.Read()
ro = data.NewRow
ro.Item(0) = CType(reader.GetValue(0), Integer)
ro.Item(1) = CType(reader.GetString(1), String)
ro.Item(2) = CType(reader.GetString(2), String)
ro.Item(3) = CType(reader.GetString(3), String)
ro.Item(4) = CType(reader.GetString(4), String)
data.Rows.Add(ro)
Loop
reader.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
Conn.Close()
End Try
This is what the table in the database looks like
Item Number | Part Number | Box Number | Description |Exeptions
1 H3300TB Box P3 Monitor Nothing
ok and here is all most the same code and it works just fine
Dim loc As String
loc = System.Environment.CurrentDirectory
loc = Microsoft.VisualBasic.Left(loc, loc.Length - 3)
Dim sConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + loc + "Inventory.mdb"
Dim Conn As New OleDb.OleDbConnection(sConnString)
Try
Dim sCommand As String = "Select [systemName] From System"
Conn.Open()
Dim Command As New OleDb.OleDbCommand(sCommand, Conn)
Dim reader As OleDb.OleDbDataReader
reader = Command.ExecuteReader
Do While reader.Read()
lbsystem.Items.Add(reader.GetString(0))
Loop
reader.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
Conn.Close()
End Try
The Image attached is of the erroe