I got around and around without finding nothing useful for creating an ADO.NET connection to an access database... Finally I got it working and now I post here the code:
I hope this will be usefulVB Code:
Dim myConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0...." ' Put here the connection string Dim mySelectQuery As String = "SELECT * FROM table" 'This is your sql query Dim myConnection As New System.Data.OleDb.OleDbConnection(myConnString) 'Create a new connection Dim myCommand As New System.Data.OleDb.OleDbCommand(mySelectQuery, myConnection) Dim myReader As System.Data.OleDb.OleDbDataReader = myCommand.ExecuteReader() myConnection.Open() ' Open Connection Try While myReader.Read() ' Read all records ' Do what you want with data... ' Use myReader. methods to retrive your data: ' myReader.GetInt32(0) gets a 32-bit int from 1st field (zero-based) ' myReader.GetString(1) gets a string from 2nd field.... ' For exampe: MsgBox(myReader.GetInt32(0).ToString() + ", " + myReader.GetString(1)) End While Finally ' Close connection myReader.Close() myConnection.Close() End Try
Xmas.




Reply With Quote