ADO Database
ADO Database
ADO Database
ADO Database
ADO Database
ADO Database ADO Database ADO Database ADO Database ADO Database ADO Database ADO Database ADO Database
ADO Database ADO Database
ADO Database
Go Back  Xtreme Visual Basic Talk > > > ADO Database


Reply
 
Thread Tools Display Modes
  #1  
Old 02-26-2013, 09:43 AM
randtek's Avatar
randtek randtek is offline
Contributor
 
Join Date: Jun 2002
Location: the Milky Way Galaxy
Posts: 532
Default ADO Database


Hello everyone. I think I should reintroduce myself, I used to be fairly active on this forum from 2002-2007, but I have not been on here since then. I am quite proficient in VB6, but new to VB.Net. I have a complex program I have been writing/maintaining for over 10 years. It is a hand coded ADO front end to an Access97 database. I use the program every day at work. For various reasons, I have decided it is time to begin rewriting this program under VB.Net. This is where my problem begins. I am finding the learning curve for VB.Net vs VB6 to be quite difficult to overcome. I am figuring out the basics, but ADO is not going well. I cannot relate ADO.Net to how I was using ADO under VB6. Some questions I have:

Will I need to update the database format from Access97 format?

Where do I find the Recordset object in ADO.Net?

Are their any good tutorials on ADO in VB.Net? I have been going through one, but it does not seem to be adequate for my needs.

I cannot even seem to figure out my connection strings under ADO.net. Are there any good code examples I can look at to see how these things are done under .net?

If anyone can help point me in a direction that might get me started, I would greatly appreciate it. This is all getting very frustrating. I have taught myself all versions of Basic programming from GWBasic, to qBasic, then VB4.5 through 6. Maybe my brain is getting too old for this!
__________________
Murphy was an optimist!
Reply With Quote
  #2  
Old 02-26-2013, 04:26 PM
Gruff's Avatar
GruffADO Database Gruff is offline
Bald Mountain Survivor

Retired Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA - deceased
Posts: 6,440
Default

Once you get use to it you will find the tools more powerful than VB6.

Code:
Public Class Form1 ' Notice how little code is needed as we have encapsulated the database routines in the class below. ' The good news is you can put the AccessDB class into a class library. Compile it ' In the future just reference it in a new project to use it. Dim oDB As New AccessDB Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click Dim sDbPath as string = "C:\Users\Gruffy\My Documents\Test22.mdb" Dim oDV As DataView = oDB.ReadAccess(sDbPath, "Select * from tblTest", "Tester", 20) Grid.DataSource = oDV End Sub End Class




Code:
' New Class to get a dataview of the query. ' Dataviews are nice as you can further filter data or sort on the fly. Imports System.Data.OleDb Public Class AccessDB Public Function ReadAccess(ByVal sDbPath as string, ByVal sSQL As String, ByVal TableName As String, ByVal WaitTime As Integer) As DataView Dim sConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & sDbPath & ";User Id=admin;Password=;" If WaitTime < 15 Then WaitTime = 15 Dim Conn As OleDb.OleDbConnection = New OleDb.OleDbConnection(sConn) Conn.Open() Dim cmd As OleDb.OleDbCommand cmd = Conn.CreateCommand() cmd.CommandText = sSQL cmd.CommandTimeout = WaitTime Dim DA = New OleDb.OleDbDataAdapter DA.SelectCommand = cmd Dim DT As New DataTable Try DA.Fill(DT) DT.TableName = TableName Catch ex As Exception MessageBox.Show("My Error: " & ex.Message) Return Nothing End Try Dim DV = New DataView DV = DT.DefaultView DV.AllowNew = False DV.AllowEdit = False Conn.Close() DT.Dispose() DT = Nothing DA.Dispose() DA = Nothing Conn.Dispose() Conn = Nothing Me.Finalize() Return DV End Function End Class
__________________
Burn the land and boil the sea
You can't take the sky from me


~T

Last edited by Gruff; 03-03-2013 at 11:43 PM.
Reply With Quote
  #3  
Old 02-26-2013, 05:53 PM
randtek's Avatar
randtek randtek is offline
Contributor
 
Join Date: Jun 2002
Location: the Milky Way Galaxy
Posts: 532
Default

Thanks for the code Gruff. That gives me something to study and try to get my head around. I do see that it will read the old access format, using Jet OleDB. Are there any references I need to set in the dev environment? or is all of this native in VB.Net. (I am using the free VB2010 Express version, registered)
__________________
Murphy was an optimist!
Reply With Quote
  #4  
Old 02-27-2013, 01:19 AM
Gruff's Avatar
GruffADO Database Gruff is offline
Bald Mountain Survivor

Retired Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA - deceased
Posts: 6,440
Default

Out of the box vb.net 2010 has a reference to 'System.Data'. Notice the imports statement at the top of the class.

Actually looking over the ReadAccess function() I would add a parameter for the full file name to the .mdb instead of hard coding it in the connection string.
__________________
Burn the land and boil the sea
You can't take the sky from me


~T
Reply With Quote
  #5  
Old 03-03-2013, 01:49 PM
randtek's Avatar
randtek randtek is offline
Contributor
 
Join Date: Jun 2002
Location: the Milky Way Galaxy
Posts: 532
Default

Thanks for your code samples Gruff. They got me started, and I have made much progress over the last few days. I think I'm starting to get it . . . at least some of it!
__________________
Murphy was an optimist!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
ADO Database
ADO Database
ADO Database ADO Database
ADO Database
ADO Database
ADO Database ADO Database ADO Database ADO Database ADO Database ADO Database ADO Database
ADO Database
ADO Database
 
ADO Database
ADO Database
 
-->