VB.NET 2002 and access, Please help

  • Thread starter Thread starter john smith
  • Start date Start date
J

john smith

Hi all I hope someone can help me. I am new to VB.NET I am trying to connect
to an access database from a windows form and it is driving me nuts, could
anyone lay it out for me?
thanks all
 
You should connect using the access provider. I believe but not sure it is
system.data.accessclient as the namespace you need to import to get to the
classes. From that point, the connections, command objects are the same as
any other connection to another database. so you could potentially google
for connection code and copy paste it in your solution, and change the
provider to use the access providers and it should just work

--
Regards,
Alvin Bruney - ASP.NET MVP

[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
Now available @ www.lulu.com/owc, Amazon.com etc
 
The provider is specified in the connection string. There is no
AccessClient namespace.

To connect to access, do the following:

Imports System.Data.OleDb
Dim conStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source =" &
Server.MapPath(relativePathToDatabase)
Dim cmdStr As String = "SELECT blah FROM blah..."
Din con As New OleDbConnection(conStr)
Dim cmd As New OleDbCommand(cmdStr, con)
Dim dr As OleDbDataReader
Try
con.Open
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
If dr.HasRows
Do While dr.Read
'You can now extract field information from the current record
using: dr.Item("fieldName")
Loop
End If
Catch ex As OleDbException
'Handle exceptions here
Finally
con.Close()
End Try


Alvin Bruney said:
You should connect using the access provider. I believe but not sure it is
system.data.accessclient as the namespace you need to import to get to the
classes. From that point, the connections, command objects are the same as
any other connection to another database. so you could potentially google
for connection code and copy paste it in your solution, and change the
provider to use the access providers and it should just work

--
Regards,
Alvin Bruney - ASP.NET MVP

[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
Now available @ www.lulu.com/owc, Amazon.com etc
john smith said:
Hi all I hope someone can help me. I am new to VB.NET I am trying to
connect to an access database from a windows form and it is driving me
nuts, could anyone lay it out for me?
thanks all
 
I'll take your word for it. Thanks

--
Regards,
Alvin Bruney - ASP.NET MVP

[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
Now available @ www.lulu.com/owc, Amazon.com etc
Scott M. said:
The provider is specified in the connection string. There is no
AccessClient namespace.

To connect to access, do the following:

Imports System.Data.OleDb
Dim conStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source =" &
Server.MapPath(relativePathToDatabase)
Dim cmdStr As String = "SELECT blah FROM blah..."
Din con As New OleDbConnection(conStr)
Dim cmd As New OleDbCommand(cmdStr, con)
Dim dr As OleDbDataReader
Try
con.Open
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
If dr.HasRows
Do While dr.Read
'You can now extract field information from the current record
using: dr.Item("fieldName")
Loop
End If
Catch ex As OleDbException
'Handle exceptions here
Finally
con.Close()
End Try


Alvin Bruney said:
You should connect using the access provider. I believe but not sure it
is system.data.accessclient as the namespace you need to import to get to
the classes. From that point, the connections, command objects are the
same as any other connection to another database. so you could
potentially google for connection code and copy paste it in your
solution, and change the provider to use the access providers and it
should just work

--
Regards,
Alvin Bruney - ASP.NET MVP

[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
Now available @ www.lulu.com/owc, Amazon.com etc
john smith said:
Hi all I hope someone can help me. I am new to VB.NET I am trying to
connect to an access database from a windows form and it is driving me
nuts, could anyone lay it out for me?
thanks all
 
Back
Top