Hi
Could any one brefily tell me how to connect and access data base use ADO.net and to put the data in a datagrid.
thanx
Printable View
Hi
Could any one brefily tell me how to connect and access data base use ADO.net and to put the data in a datagrid.
thanx
Heres the code
'Create connection to Access DB and open
Dim oConn As New OleDbConnection()
Try
With oConn
.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "\db.mdb;"
.Open()
End With
Catch
End Try
'Create a command object with SQL statement
Dim oCmd As New OleDbCommand()
With oCmd
.Connection = oConn
.CommandText = "SELECT * FROM UserDetails"
End With
' Fill Dataset with results
Try
Dim oDS As New DataSet()
Dim oDA As New OleDbDataAdapter(oCmd)
oDA.Fill(oDS, "UserDetails")
'Set the datasource of the datagrid to the table in the dataset
DataGrid1.DataSource = oDS.Tables("UserDetails")
Catch
End Try
Try
'Close the connection and set to nohing
oConn.Close()
oConn = Nothing
Catch
End Try