By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,258 Members | 1,316 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,258 IT Pros & Developers. It's quick & easy.

Query database in VB.NET

P: n/a
I would like to create a query to run in a VB.NET application that searches
an Access contacts database for 1 or more strings, e.g. FirstName, LastName
etc. and returns the results in a DataGrid.

Can this be done and if so can anyone offer me any assistance?

Thanks
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"gregas" <gr****@discussions.microsoft.com> wrote in message
news:B6**********************************@microsof t.com...
I would like to create a query to run in a VB.NET application that searches
an Access contacts database for 1 or more strings, e.g. FirstName,
LastName
etc. and returns the results in a DataGrid.

Can this be done and if so can anyone offer me any assistance?

Thanks


Yes, it can be done. You might start by checking out the System.Data.OleDb
namespace in MSDN Online. A handy resource for learning how to use the
Connection, DataAdapter, DataSet, etc., is to use the Data Form Wizard and
look at the form and code it creates.
Nov 21 '05 #2

P: n/a
On Wed, 23 Mar 2005 15:15:03 -0800, gregas <gr****@discussions.microsoft.com> wrote:

I would like to create a query to run in a VB.NET application that searches
an Access contacts database for 1 or more strings, e.g. FirstName, LastName
etc. and returns the results in a DataGrid.

Can this be done and if so can anyone offer me any assistance?

Rather simple example should get you started:

Dim ConnectionString As String

ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=e:\My Documents\db1.mdb"
Dim AccessConnection As New System.Data.OleDb.OleDbConnection(ConnectionString )
AccessConnection.Open()

Dim da As New System.Data.OleDb.OleDbDataAdapter("SELECT * FROM Contacts WHERE...(add your
criteria here) ", AccessConnection)

Dim ds As New DataSet

da.Fill(ds, "Contacts")

DataGrid1.SetDataBinding(ds, "Contacts")

AccessConnection.Close()
Paul
~~~~
Microsoft MVP (Visual Basic)
Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.