Home All Groups Group Topic Archive Search About

Query database in VB.NET

Author
23 Mar 2005 11:15 PM
gregas
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

Author
24 Mar 2005 2:02 PM
Paul Clement
On Wed, 23 Mar 2005 15:15:03 -0800, gregas <gre***@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)
Author
28 Mar 2005 12:15 PM
lukegregory
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

Show quoteHide quote
"Paul Clement" wrote:

> On Wed, 23 Mar 2005 15:15:03 -0800, gregas <gre***@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)
>
Author
28 Mar 2005 7:40 PM
Michael C#
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...

Show quoteHide quote
"lukegregory" <lukegreg***@discussions.microsoft.com> wrote in message
news:58DB16F0-44E5-4477-B0AD-E3F37765998E@microsoft.com...
> 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
>
> "Paul Clement" wrote:
>
>> On Wed, 23 Mar 2005 15:15:03 -0800, gregas
>> <gre***@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)
>>
Author
28 Mar 2005 7:44 PM
james
Here is a link to a very good example of what you are looking for. (in fact this example does much more)
james

http://planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=1991&lngWId=10






Show quoteHide quote
"lukegregory" <lukegreg***@discussions.microsoft.com> wrote in message
news:58DB16F0-44E5-4477-B0AD-E3F37765998E@microsoft.com...
> 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
>
> "Paul Clement" wrote:
>
>> On Wed, 23 Mar 2005 15:15:03 -0800, gregas <gre***@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)
>>