|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Help with Access Database and tablesI am trying to convert to vb.net from VB6 and I am haveing a major problem with connecting to an Access database and adding, updating, deleting data. This is what I usually use in vb6: sqlText As String dbConn As New ADODB.Connection rsConn As ADODB.Recordset dbConn.Provider = "Microsoft.Jet.OLEDB.4.0" dbConn.Properties("Data Source") = App.Path & "\mydatabase.mdb" dbConn.Open sqlText = "SELECT * FROM publishers WHERE series=1" Set rsConn = New ADODB.Recordset rsConn.Open sqlText And to read : while not rsconn.eof text1=rsconn("field1") rsconn.movenext wend I do not use SQL, since the database is local to the app and since I do not have SQL. So please, any assistance/guidance/etc would be greatly appreciated. George Here's a simple data access class you can download that demonstrates how to
access SQL Server databases and/or Access databases. (www.dxonline.com/files/clsData.vb) This can be adapted to other databases, assuming the proper drivers and references are present. Here's an example of how to get a dataset, make changes to it, and update it back to the database: Dim dsList As DataSet = clsData.LoadDataSet("Select * from Customers Where CustID = 100", gsDriver, gsLocation, sDatabase) If dsList.Tables(0).Rows.Count <> 0 Then dsList.Tables(0).Row(0).Item("CustType") = "NOP" clsData.UpdateDataSet(dsList, "Select * from Customers Where CustID = 100", gsDriver, gsLocation, gsDatabase) End If Changing gsDriver between "SQL" and "ACCESS" tells the class what kind of database to use. gsLocation is either the path to the Access database, or it's the server name for the SQL Server. gsDatabase is the name of the Access database file, or the name of the SQL database. -- Show quoteHide quote------------------------------------------------------------------------ George Shubin Custom Software Development dX Software Systems Database Applications Ph: 503-981-6806 Fax: 503-982-0120 www.dxonline.com geo***@dxonline.com ------------------------------------------------------------------------ "In politics an absurdity is not a handicap." -- Napoleon Bonaparte "George" <Geo***@discussions.microsoft.com> wrote in message news:750B1042-78DF-4281-8B2E-A94C191A34D4@microsoft.com... > Hi all, > > I am trying to convert to vb.net from VB6 and I am haveing a major problem > with connecting to an Access database and adding, updating, deleting data. > > This is what I usually use in vb6: > > sqlText As String > dbConn As New ADODB.Connection > rsConn As ADODB.Recordset > > dbConn.Provider = "Microsoft.Jet.OLEDB.4.0" > dbConn.Properties("Data Source") = App.Path & "\mydatabase.mdb" > dbConn.Open > > sqlText = "SELECT * FROM publishers WHERE series=1" > > Set rsConn = New ADODB.Recordset > rsConn.Open sqlText > > > And to read : > > while not rsconn.eof > text1=rsconn("field1") > rsconn.movenext > wend > > > I do not use SQL, since the database is local to the app and since I do > not > have SQL. > > So please, any assistance/guidance/etc would be greatly appreciated. > > George George,
I appreciate your help, but when I went to get the class file, I got an error. I would like to see it if possible. Thanks, George Show quoteHide quote "George Shubin" wrote: > Here's a simple data access class you can download that demonstrates how to > access SQL Server databases and/or Access databases. > (www.dxonline.com/files/clsData.vb) > > This can be adapted to other databases, assuming the proper drivers and > references are present. > > Here's an example of how to get a dataset, make changes to it, and update it > back to the database: > > > Dim dsList As DataSet = clsData.LoadDataSet("Select * from Customers Where > CustID = 100", gsDriver, gsLocation, sDatabase) > > If dsList.Tables(0).Rows.Count <> 0 Then > dsList.Tables(0).Row(0).Item("CustType") = "NOP" > clsData.UpdateDataSet(dsList, "Select * from Customers Where CustID = > 100", gsDriver, gsLocation, gsDatabase) > End If > > > > Changing gsDriver between "SQL" and "ACCESS" tells the class what kind of > database to use. > gsLocation is either the path to the Access database, or it's the server > name for the SQL Server. > gsDatabase is the name of the Access database file, or the name of the SQL > database. > > > -- > ------------------------------------------------------------------------ > George Shubin Custom Software Development > dX Software Systems Database Applications > Ph: 503-981-6806 Fax: 503-982-0120 > www.dxonline.com geo***@dxonline.com > ------------------------------------------------------------------------ > > "In politics an absurdity is not a handicap." -- Napoleon Bonaparte > > "George" <Geo***@discussions.microsoft.com> wrote in message > news:750B1042-78DF-4281-8B2E-A94C191A34D4@microsoft.com... > > Hi all, > > > > I am trying to convert to vb.net from VB6 and I am haveing a major problem > > with connecting to an Access database and adding, updating, deleting data. > > > > This is what I usually use in vb6: > > > > sqlText As String > > dbConn As New ADODB.Connection > > rsConn As ADODB.Recordset > > > > dbConn.Provider = "Microsoft.Jet.OLEDB.4.0" > > dbConn.Properties("Data Source") = App.Path & "\mydatabase.mdb" > > dbConn.Open > > > > sqlText = "SELECT * FROM publishers WHERE series=1" > > > > Set rsConn = New ADODB.Recordset > > rsConn.Open sqlText > > > > > > And to read : > > > > while not rsconn.eof > > text1=rsconn("field1") > > rsconn.movenext > > wend > > > > > > I do not use SQL, since the database is local to the app and since I do > > not > > have SQL. > > > > So please, any assistance/guidance/etc would be greatly appreciated. > > > > George > > >
what's up? reading xml
Best Practices - Coding Convention Question How do you know when all databindings on form are complete? Reading Excel in VB.NET How to update data in Windows Datagrid DoEvents in VB.NET Committing Byte Array to Disk Building VB.NET Interface definitions from a COM interface Process BUG? drag / drop list view items from two list views |
|||||||||||||||||||||||