Access Database

  • Thread starter Thread starter Lou
  • Start date Start date
L

Lou

Where can I find sample code to connect/use an Access DB, all the microsoft
samples require SQL and I don't have that. This will be my first .Net app!

Scared...
 
I can't get it to work?
Why doesn't my grid populate

Dim conn As New OleDbConnection

Dim myData As OleDbDataReader

Dim cmd As New OleDbCommand

Dim connString As String

Dim i As Integer

Try

' Set the connection string.

connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= D:\Lou
Projects\Projects.mdb"

' Open the connection.

conn.ConnectionString = connString

conn.Open()

'Set the command properties.

cmd.Connection = conn

cmd.CommandText = "SELECT * from client"

myData = _

cmd.ExecuteReader(CommandBehavior.CloseConnection)

Try

While (myData.Read)

'Process data.

DataGrid1.DataSource = myData

End While

Finally

myData.Close()

End Try

Catch ex As Exception

'Error handling

Debug.Write(Err.Description)

End Try

End Function 'GetAccessData
 
Hi,

You can not bind a window form grid to a datareader. that is only
available for the webform based one. Use a dataset instead.

Dim strConn As String

Dim strSQL As String

Dim da As OleDbDataAdapter

Dim conn As OleDbConnection

strConn = "Provider = Microsoft.Jet.OLEDB.4.0;"

strConn &= "Data Source = Northwind.mdb;"

conn = New OleDbConnection(strConn)

da = New OleDbDataAdapter("Select * From Categories", conn)

da.Fill(ds, "Categories")

DataGrid1.DataSource = ds .Tables("Categories")





Ken

--------------
I can't get it to work?
Why doesn't my grid populate

Dim conn As New OleDbConnection

Dim myData As OleDbDataReader

Dim cmd As New OleDbCommand

Dim connString As String

Dim i As Integer

Try

' Set the connection string.

connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= D:\Lou
Projects\Projects.mdb"

' Open the connection.

conn.ConnectionString = connString

conn.Open()

'Set the command properties.

cmd.Connection = conn

cmd.CommandText = "SELECT * from client"

myData = _

cmd.ExecuteReader(CommandBehavior.CloseConnection)

Try

While (myData.Read)

'Process data.

DataGrid1.DataSource = myData

End While

Finally

myData.Close()

End Try

Catch ex As Exception

'Error handling

Debug.Write(Err.Description)

End Try

End Function 'GetAccessData
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top