Query database in VB.NET

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
gregas said:
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.
 
¤ 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)
 
Hi Guys,

I have been struggling with this for days now and still cannot get it
working, I'm still quite new to VB.NET.

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

I have 8 text boxes: FirstName, LastName etc. a Search button and a DataGrid
for the results and the connection to the DB works fine, but I have no idea
how to get this to function.

I'd really appreciate any help that you could offer.

Thanks,
Luke
 
Part of the problem might be that no one knows what your database looks
like... Have you used the Data Form Wizard to create a Data Form? If you
decide to, point it at your database and then take a look at the code it
generates. It's a starting point...
 

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