|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Query database in VB.NETI 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 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) 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) > 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) >> 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) >>
Only Numeric Values in the textbox
record locking with DBF (visual basic) table in ADO OLEDB in VB.NET Create ListView columns dynamically from XML Set Desktop Search and Replace using WildCards replace oddity Setup problem How to have embeded pictures in a project need ideas - how to determine when another machine has persisted a file VBScript tutorials |
|||||||||||||||||||||||