To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
VBForums  

VB Wire News
Article :: Building Dynamic Systems with Expressions in .NET
How Is XML Like An Interface?
Understanding Covariance and Contravariance
Print VS 2010 Keyboard Shortcut References in Letter (8.5x11in) and A4 (210×297mm) Sizes
Updated Productivity Power Tools



Go Back   VBForums > Visual Basic > Database Development

Closed Thread Post New Thread
 
Thread Tools Display Modes
Old Mar 20th, 2002, 06:04 PM   #1
Beacon
PowerPoster
 
Beacon's Avatar
 
Join Date: Jan 01
Location: Pub Floor
Posts: 3,188
Beacon  is on a distinguished road (40+)
Smile ADO Beginners Tutorial

G'day folks,

Just thought i'd attach my "An introduction to ADO" tutorial for anyone wanting to learn how to work with databases or wanting to learn how to use ADODB.

It is for beginners so it's not too complicated hopefully it's easy enough to read and understand.

It's password protected so just choose read-only when you open it.

cheers
beacon



added by si_the_geek:

Note that there are some bugs in this tutorial, you can find a corrected version of the tutorial in the thread: ADO Tutorial for Classic VB


If anyone wants to ask a question relating to the tutorial, the chances are that it has already been answered in this thread (so please read the replies!), or is in the thread ADO Beginners Tutorial, Some Further Steps.

If you cannot find an answer to your question, please create a new thread in the Database Development forum - several people who can help will read it.
Attached Files
File Type: zip an introduction to ado.zip (8.9 KB, 15241 views)

Last edited by si_the_geek; Jan 28th, 2009 at 06:11 PM.
Beacon is offline  
Old Apr 14th, 2002, 09:32 PM   #2
BTi
New Member
 
Join Date: Apr 02
Posts: 3
BTi is an unknown quantity at this point (<10)
Your ADO tutorial was unbelievably helpful. Hats off to you.

One question:

If my database file(DB1.mdb) is not on my harddrive and is actually on the internet, what changes do I have to make to the code in order to access it?

I've tried everything and nothing worked.

Thank you so much.

Again, your tutorial was superb.
BTi is offline  
Old Apr 14th, 2002, 09:41 PM   #3
mendhak
ASP.NET Moderator
 
mendhak's Avatar
 
Join Date: Feb 02
Location: Ulaan Baator GooGoo: Frog
Posts: 38,150
mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)
You can get connection strings for ADO here:

http://www.able-consulting.com/ado_conn.htm
mendhak is offline  
Old Apr 14th, 2002, 09:43 PM   #4
Beacon
PowerPoster
 
Beacon's Avatar
 
Join Date: Jan 01
Location: Pub Floor
Posts: 3,188
Beacon  is on a distinguished road (40+)
Yeah but they arent as helpful as my tutorial!

Anyways instead of the pc name put in the ip address of the computer with the db in it!

Later
b
Beacon is offline  
Old Apr 15th, 2002, 02:11 AM   #5
hiyuka
Guest
 
Posts: n/a
your file used password protect.
I can't read tell me password please.
 
Old Apr 15th, 2002, 02:23 AM   #6
WiseGuy
Lively Member
 
WiseGuy's Avatar
 
Join Date: Apr 02
Location: Zierikzee, The Netherlands
Posts: 98
WiseGuy is an unknown quantity at this point (<10)
Quote:
It's password protected so just choose read-only when you open it.
first read before asking!


The WiseGuy
__________________
I stuck my head out of the window and got arrested for mooning!

This Post is sponsored by my PC: PIII900, 512MBDimm/133, Seagate 40GB/7200 ATA100, LiteOn 12x DVD, Lite-On 32x12x40 CDrw, Elsa Geforce2 Ultra 64MB incl tv-out, SoundBlaster Live 1024, Ilyama A702HT Vision Master Pro410 17".
O/S: Windows XP Professional (dutch)
Internet: Cable (1Mbit connection)
WiseGuy is offline  
Old May 24th, 2002, 11:27 AM   #7
The Hobo
Stuck in the 80s
 
The Hobo's Avatar
 
Join Date: Jul 01
Location: Michigan
Posts: 7,254
The Hobo  is on a distinguished road (40+)
Great tutorial Beacon! You might wanna run through it with a spell check though Also, first you say that you're going to refer to the table as 'table1' then you say 'tbl_master' throughout the document.

But well done. Very helpful
__________________
My evil laugh has a squeak in it.

kristopherwilson.com
The Hobo is offline  
Old May 26th, 2002, 07:10 PM   #8
Beacon
PowerPoster
 
Beacon's Avatar
 
Join Date: Jan 01
Location: Pub Floor
Posts: 3,188
Beacon  is on a distinguished road (40+)
hehehe

Whoops!

Keeping ya on ya toes!
Thanks hobo!
b
Beacon is offline  
Old Dec 25th, 2003, 02:55 AM   #9
Kracked
New Member
 
Join Date: Dec 03
Location: canada
Posts: 10
Kracked is an unknown quantity at this point (<10)
Question

Hiya Beacon
Loved the tutorial, was a big help.
Question I have tho, is I'm trying to make a table bigger than what access will allow me to create.
My table on my form is 20 rows deep by 10 columns wide, and each textbox in it needs a spot in the database.
You know a way around that?
Thx in advance

*by the way...something I added to yours on my own, (I was proud cuz I'm as newbie as newbie gets hehe), is that if you dont have a pre programmed database record when you go to start the project it'll come up with an error and shut down. So on Form_load I did this at the bottom....

If (rs.BOF = True Or rs.EOF = True) Then
Call Init
Else:
rs.MoveFirst 'moves to the first record
fillfields
End If

Sub Init() is where i have all my textboxes set at zero...for when a user first uses a program or is starting a new file, etc etc
Opens up fine with a record in it or not.
I've been teaching myself over the past 3 or 4 months with a few books and forums like this as I muddle my way thru my first project
__________________
~ Hardest working newbie on the net ~
Kracked is offline  
Old Dec 25th, 2003, 11:13 AM   #10
mendhak
ASP.NET Moderator
 
mendhak's Avatar
 
Join Date: Feb 02
Location: Ulaan Baator GooGoo: Frog
Posts: 38,150
mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)
Re: Question

Quote:
Originally posted by Kracked
Hiya Beacon
Loved the tutorial, was a big help.
Question I have tho, is I'm trying to make a table bigger than what access will allow me to create.
My table on my form is 20 rows deep by 10 columns wide, and each textbox in it needs a spot in the database.
You know a way around that?
Thx in advance


Hmm... I don't know if Beacon still visits this place.

AFAIK, Access has no such limits. Perhaps you're talking about the form you're creating in VB being limited by size? If such is the case, how about using a grid?
mendhak is offline  
Old Jan 18th, 2004, 08:11 PM   #11
Mike Collier
Lively Member
 
Join Date: Apr 02
Location: UK
Posts: 90
Mike Collier is an unknown quantity at this point (<10)
ADO help can be obtained here too now:

http://www.adoanywhere.com

You can get online help in the forum and download the worlds most powerful ADO Browser:

Mike Collier.
Mike Collier is offline  
Old Apr 8th, 2004, 07:34 PM   #12
Adnane
New Member
 
Join Date: Mar 04
Posts: 7
Adnane is an unknown quantity at this point (<10)
How can I submit to a different table or query, I used beacon's tutorial and I got the information from 2 different tables but now I need to submit to a different table.

Thank you
Adnane is offline  
Old Apr 9th, 2004, 05:27 AM   #13
mendhak
ASP.NET Moderator
 
mendhak's Avatar
 
Join Date: Feb 02
Location: Ulaan Baator GooGoo: Frog
Posts: 38,150
mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)
Store the values into variables.

Then, use the connection object's EXECUTE method to execute the SQL INSERT query.
mendhak is offline  
Old Apr 9th, 2004, 10:20 AM   #14
alx100
New Member
 
Join Date: Apr 04
Posts: 7
alx100 is an unknown quantity at this point (<10)
can you also use ADO to link a database to a bar chart?

if so, what code is it/change?

thanks
alx100 is offline  
Old Apr 11th, 2004, 01:36 AM   #15
mendhak
ASP.NET Moderator
 
mendhak's Avatar
 
Join Date: Feb 02
Location: Ulaan Baator GooGoo: Frog
Posts: 38,150
mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)
Quote:
Originally posted by alx100
can you also use ADO to link a database to a bar chart?

if so, what code is it/change?

thanks
A chart is a separate control (and issue). If the chart in question has a provision of working with recordsets, then you probably need to just set the recordset there.

Otherwise, it probably works off arrays, so you should store the values from your recordset into an array and then pass the array to the chart.
mendhak is offline  
Old Apr 11th, 2004, 04:47 AM   #16
alx100
New Member
 
Join Date: Apr 04
Posts: 7
alx100 is an unknown quantity at this point (<10)
hi, thanks there,

do you have any examples, or show how this code should be written?

i have never done this or MS Chart before,

thank you!
alx100 is offline  
Old Apr 11th, 2004, 06:17 AM   #17
mendhak
ASP.NET Moderator
 
mendhak's Avatar
 
Join Date: Feb 02
Location: Ulaan Baator GooGoo: Frog
Posts: 38,150
mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)
mendhak is offline  
Old Oct 21st, 2004, 01:24 PM   #18
Nove
Fanatic Member
 
Nove's Avatar
 
Join Date: Jul 04
Posts: 736
Nove is on a distinguished road (20+)
Hey can anyone point me to where I can download the adodb control? It's not in my components list. I've been searching and I can't find it...
Nove is offline  
Old Oct 25th, 2004, 12:24 AM   #19
mendhak
ASP.NET Moderator
 
mendhak's Avatar
 
Join Date: Feb 02
Location: Ulaan Baator GooGoo: Frog
Posts: 38,150
mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)
Project > References
mendhak is offline  
Old Dec 3rd, 2004, 07:03 AM   #20
nacho2
Lively Member
 
Join Date: Nov 04
Posts: 70
nacho2 is an unknown quantity at this point (<10)
Re: ADO Beginners Tutorial

Don't know if this thread is still in use but there it goes anyway:

I got all my data in a dataset and now I'm trying to change 'field1' in 'table1'. I know there is a command dataset.select(..filter...) isn't there anything like dataset.update or something like that?

And what could I do to change a value of a row of a table?

Thanks in advance.
nacho2 is offline  
Old Dec 3rd, 2004, 07:04 AM   #21
mendhak
ASP.NET Moderator
 
mendhak's Avatar
 
Join Date: Feb 02
Location: Ulaan Baator GooGoo: Frog
Posts: 38,150
mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)
Re: ADO Beginners Tutorial

Use the DataAdapter's update method to update the db with changes made in the dataset.
mendhak is offline  
Old Dec 3rd, 2004, 08:11 AM   #22
nacho2
Lively Member
 
Join Date: Nov 04
Posts: 70
nacho2 is an unknown quantity at this point (<10)
Re: ADO Beginners Tutorial

Nope, I don't think that helps in my case. My database is an xml database, so I'm using no dataadapter, just the dataset. And the thing is that the change in the data comes from the user he clicks the button that says 'erase entry' and then I want the 'erased' field to be set to true. So I need to be able to do Dataset.Table.Change(...) if it existed, and then run Dataset.WriteXml(..).

So I wanna change the dataset and then write the xml.

Am I missing something I should be using like a dataadapter or something like that?

Thanks
nacho2 is offline  
Old Dec 21st, 2004, 09:36 PM   #23
Broken Soul
New Member
 
Join Date: Dec 04
Posts: 2
Broken Soul is an unknown quantity at this point (<10)
Re: ADO Beginners Tutorial

what if you dont have ms access 2000. how can i save things to lables or text boxes or something?
Broken Soul is offline  
Old May 14th, 2005, 11:37 PM   #24
longwolf
Frenzied Member
 
longwolf's Avatar
 
Join Date: Oct 02
Posts: 1,343
longwolf will become famous soon enough (80+)
Re: ADO Beginners Tutorial

This thread looks dead but I thought I'd try anyway.
I'm completely new at working with DBs.
I copied the code from Beacon's tut and added the reference.
Made a DB in Access 2002
One table with three fields.
Stored the table in the same folder as the VB project and altered the path in the form load event.

WHen I get to line:
Code:
cn.Open
I get:
'Run tome error -yada yada
Authentication failed'

Clicking 'Help' just says 'no help on subject'

Not a great start.
What do I do?
longwolf is offline  
Old May 15th, 2005, 01:57 AM   #25
mendhak
ASP.NET Moderator
 
mendhak's Avatar
 
Join Date: Feb 02
Location: Ulaan Baator GooGoo: Frog
Posts: 38,150
mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)
Re: ADO Beginners Tutorial

Show all the code you've used, not just that one line.
mendhak is offline  
Old May 15th, 2005, 01:04 PM   #26
longwolf
Frenzied Member
 
longwolf's Avatar
 
Join Date: Oct 02
Posts: 1,343
longwolf will become famous soon enough (80+)
Re: ADO Beginners Tutorial

It all comes strait from the tutorial.
The only line I changed was the path to db1.mdb in Form_Load.

VB Code:
  1. Option Explicit
  2. Private cn As ADODB.Connection 'this is the connection
  3. Private rs As ADODB.Recordset 'this is the recordset
  4. Private Sub Form_Load()
  5.     Me.MousePointer = 11 'this makes the mouse pointer the hourglass
  6.    
  7.     Set cn = New ADODB.Connection 'we've declared it as a ADODB connection lets set it.
  8.     cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
  9.       App.Path & "\db1.mdb"  'this is the connection string explained in the notes section.
  10. 'The next line is where I get the error
  11.     cn.Open
  12.     Set rs = New ADODB.Recordset 'as we did with the connection
  13.     rs.Open "tbl_master", cn, adOpenKeyset, adLockPessimistic, adCmdTable 'opening the recordset explained in the notes
  14.            
  15.     rs.MoveFirst 'moves to the first record
  16.     Do Until rs.EOF = True 'this is the Loop to add items to the combo box
  17.         combo1.AddItem rs.Fields("field1") 'this adds items from field1 into the combo box
  18.         rs.MoveNext 'moves next record
  19.     Loop
  20.     rs.MoveFirst
  21.     fillfields 'i'll explain this later on.
  22.    
  23.     Me.MousePointer = 0 'sets the mouse pointer to the normal arrow
  24. End Sub
  25. Public Sub fillfields()
  26.     If Not (rs.BOF = True Or rs.EOF = True) Then 'Checks if we are at the first or last record. This is use a lot.
  27.         Text1.Text = rs.Fields("Field2") 'text1 = field2 and display that data
  28.         Text2.Text = rs.Fields("Field3") 'as above
  29.         combo1.Text = rs.Fields("Field1") 'as above
  30.     Else
  31.         MsgBox "Either you are at the first record or the last record.", vbExclamation, "Cannot Move"
  32.     End If
  33. End Sub
  34. Private Sub cmdPrev_Click()
  35.     If Not (rs.BOF = True) Then
  36.         rs.MovePrevious 'move previous record
  37.         fillfields 'fill the controls
  38.     End If
  39. End Sub
  40. Private Sub cmdNext_Click()
  41.     If Not (rs.EOF = True) Then
  42.         rs.MoveNext 'move to next record
  43.         fillfields 'fill the controls
  44.     End If
  45. End Sub
  46. Private Sub cmdAdd_Click()
  47.     With rs
  48.         .AddNew 'adding new record
  49.         .Fields("field2") = Text1.Text 'setting field2 = whatever is typed in text1
  50.         .Fields("field3") = Text2.Text 'as above
  51.         .Fields("field1") = combo1.Text 'as above
  52.         .Update 'this updates the recordset etc.
  53.     End With
  54. End Sub
  55. Private Sub cmdDelete_Click()
  56.     If MsgBox("Are you sure you want to delete this record?", vbYesNo + vbQuestion, "Delete?") = vbNo Then      'check if you really want to delete this record
  57.         Exit Sub 'exit the command
  58.     Else
  59.         If Not (rs.BOF = True Or rs.EOF = True) Then
  60.             rs.Delete 'delete the current record
  61.             If Not (rs.BOF = True Or rs.EOF = True) Then
  62.                 rs.MoveNext 'move next
  63.             If rs.EOF Then rs.MoveLast
  64.                 fillfields
  65.             End If
  66.         End If
  67.     End If
  68. End Sub
  69. Private Sub Form_Unload(Cancel As Integer)
  70.     rs.Close 'close the recordset
  71.     cn.Close 'close the connection
  72.     Set rs = Nothing  'set them to nothing
  73.     Set cn = Nothing 'as above
  74. End Sub

I've also attached the DB that I made to match the one Beacon discribes.
There's no info in it, just the structure.

P.S. I believe the cmdDelete_Click sub needs correcting.
But I didn't get far enough to test it.
It also comes strait from the tutorial.
Attached Files
File Type: zip Db1.zip (6.8 KB, 1060 views)

Last edited by longwolf; May 15th, 2005 at 07:59 PM.
longwolf is offline  
Old May 15th, 2005, 01:53 PM   #27
techgnome
Snarky...
 
techgnome's Avatar
 
Join Date: May 02
Posts: 15,241
techgnome has a brilliant future (2000+)techgnome has a brilliant future (2000+)techgnome has a brilliant future (2000+)techgnome has a brilliant future (2000+)techgnome has a brilliant future (2000+)techgnome has a brilliant future (2000+)techgnome has a brilliant future (2000+)techgnome has a brilliant future (2000+)techgnome has a brilliant future (2000+)techgnome has a brilliant future (2000+)techgnome has a brilliant future (2000+)
Re: ADO Beginners Tutorial

It's been a while since I used Access, but the connectionstring doesn't look quite right to me.

Tg
__________________
* I don't respond to private requests for help. It's not conducive to the general learning of others.-I also subscribe to all threads I participate, so there's no need to pm when there's an update.*
* How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
* How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to???
* On Error Resume Next is error ignoring, not error handling(tm). * Use Offensive Programming, not Defensive Programming.
"There is a major problem with your code, and VB wants to tell you what it is.. but you have decided to put your fingers in your ears and shout 'I'm not listening!'" - si_the_geek on using OERN
MVP '06-'10
techgnome is online now  
Old May 15th, 2005, 08:12 PM   #28
mendhak
ASP.NET Moderator
 
mendhak's Avatar
 
Join Date: Feb 02
Location: Ulaan Baator GooGoo: Frog
Posts: 38,150
mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)
Re: ADO Beginners Tutorial

You're right.

It should be

cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
App.Path & "\db1.mdb"
mendhak is offline  
Old May 16th, 2005, 04:31 PM   #29
longwolf
Frenzied Member
 
longwolf's Avatar
 
Join Date: Oct 02
Posts: 1,343
longwolf will become famous soon enough (80+)
Re: ADO Beginners Tutorial

That fixed it, I cut too much off when I changed the path.

Another question.
Is there a a help file for ADO?
If so where do I get it and how would you set it so that, when you get a error msg from a line with DB code, it will check the ADO help file?

I'm one of those weird people that actually use the Help Button.
longwolf is offline  
Old Sep 11th, 2005, 04:53 AM   #30
vocalmind
New Member
 
Join Date: Sep 05
Posts: 13
vocalmind is an unknown quantity at this point (<10)
Re: ADO Beginners Tutorial

On the tutorial. How to update the text on TEXT box by selecting the list on the COMBO box?

Last edited by vocalmind; Sep 11th, 2005 at 05:07 AM.
vocalmind is offline  
Old Sep 11th, 2005, 08:46 AM   #31
longwolf
Frenzied Member
 
longwolf's Avatar
 
Join Date: Oct 02
Posts: 1,343
longwolf will become famous soon enough (80+)
Re: ADO Beginners Tutorial

Quote:
Originally Posted by vocalmind
On the tutorial. How to update the text on TEXT box by selecting the list on the COMBO box?
I haven't looked at that code in a while.
Change the name of the textbox and combox in the code below so they match the tutorial code.

VB Code:
  1. Private Sub Combo1_Change()
  2.     Text1.Text = Combo1.Text
  3. End Sub
  4. Private Sub Combo1_Click()
  5.     Text1.Text = Combo1.Text
  6. End Sub

Last edited by longwolf; Sep 11th, 2005 at 08:50 AM.
longwolf is offline  
Old Sep 21st, 2005, 03:07 PM   #32
manofsteel00
Addicted Member
 
Join Date: Sep 05
Posts: 194
manofsteel00 is an unknown quantity at this point (<10)
Re: ADO Beginners Tutorial

Thanks Beacon!
manofsteel00 is offline  
Old Sep 25th, 2005, 11:51 AM   #33
lavarock09
Lively Member
 
lavarock09's Avatar
 
Join Date: Jun 05
Posts: 124
lavarock09 is an unknown quantity at this point (<10)
Re: ADO Beginners Tutorial

How do I edit it so that I can search the database for a term and it displays all the info for that term?
__________________
Userbars.co.uk
lavarock09 is offline  
Old Jan 9th, 2006, 02:41 AM   #34
zach007
Addicted Member
 
Join Date: Nov 05
Posts: 185
zach007 is an unknown quantity at this point (<10)
Re: ADO Beginners Tutorial

Quote:
Originally Posted by longwolf
VB Code:
  1. Option Explicit
  2. Private cn As ADODB.Connection 'this is the connection
  3. Private rs As ADODB.Recordset 'this is the recordset
  4. Private Sub Form_Load()
  5.     Me.MousePointer = 11 'this makes the mouse pointer the hourglass
  6.    
  7.     Set cn = New ADODB.Connection 'we've declared it as a ADODB connection lets set it.
  8.     cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
  9.       App.Path & "\db1.mdb"  'this is the connection string explained in the notes section.
  10. 'The next line is where I get the error
  11.     cn.Open
  12.     Set rs = New ADODB.Recordset 'as we did with the connection
  13.     rs.Open "tbl_master", cn, adOpenKeyset, adLockPessimistic, adCmdTable 'opening the recordset explained in the notes
  14.            
  15.     rs.MoveFirst 'moves to the first record
  16.     Do Until rs.EOF = True 'this is the Loop to add items to the combo box
  17.         combo1.AddItem rs.Fields("field1") 'this adds items from field1 into the combo box
  18.         rs.MoveNext 'moves next record
  19.     Loop
  20.     rs.MoveFirst
  21.     fillfields 'i'll explain this later on.
  22.    
  23.     Me.MousePointer = 0 'sets the mouse pointer to the normal arrow
  24. End Sub
  25. Public Sub fillfields()
  26.     If Not (rs.BOF = True Or rs.EOF = True) Then 'Checks if we are at the first or last record. This is use a lot.
  27.         Text1.Text = rs.Fields("Field2") 'text1 = field2 and display that data
  28.         Text2.Text = rs.Fields("Field3") 'as above
  29.         combo1.Text = rs.Fields("Field1") 'as above
  30.     Else
  31.         MsgBox "Either you are at the first record or the last record.", vbExclamation, "Cannot Move"
  32.     End If
  33. End Sub
  34. Private Sub cmdPrev_Click()
  35.     If Not (rs.BOF = True) Then
  36.         rs.MovePrevious 'move previous record
  37.         fillfields 'fill the controls
  38.     End If
  39. End Sub
  40. Private Sub cmdNext_Click()
  41.     If Not (rs.EOF = True) Then
  42.         rs.MoveNext 'move to next record
  43.         fillfields 'fill the controls
  44.     End If
  45. End Sub
  46. Private Sub cmdAdd_Click()
  47.     With rs
  48.         .AddNew 'adding new record
  49.         .Fields("field2") = Text1.Text 'setting field2 = whatever is typed in text1
  50.         .Fields("field3") = Text2.Text 'as above
  51.         .Fields("field1") = combo1.Text 'as above
  52.         .Update 'this updates the recordset etc.
  53.     End With
  54. End Sub
  55. Private Sub cmdDelete_Click()
  56.     If MsgBox("Are you sure you want to delete this record?", vbYesNo + vbQuestion, "Delete?") = vbNo Then      'check if you really want to delete this record
  57.         Exit Sub 'exit the command
  58.     Else
  59.         If Not (rs.BOF = True Or rs.EOF = True) Then
  60.             rs.Delete 'delete the current record
  61.             If Not (rs.BOF = True Or rs.EOF = True) Then
  62.                 rs.MoveNext 'move next
  63.             If rs.EOF Then rs.MoveLast
  64.                 fillfields
  65.             End If
  66.         End If
  67.     End If
  68. End Sub
  69. Private Sub Form_Unload(Cancel As Integer)
  70.     rs.Close 'close the recordset
  71.     cn.Close 'close the connection
  72.     Set rs = Nothing  'set them to nothing
  73.     Set cn = Nothing 'as above
  74. End Sub
Where is the code for "update data"..(cmdUpdate_Click)..please???
zach007 is offline  
Old Jan 9th, 2006, 03:02 AM   #35
longwolf
Frenzied Member
 
longwolf's Avatar
 
Join Date: Oct 02
Posts: 1,343
longwolf will become famous soon enough (80+)
Re: ADO Beginners Tutorial

I'm sorry zach007 , it's been some time since I was on this code.

I think I started with the code from the tutorial then was making changes to it to learn.
longwolf is offline  
Old Jan 9th, 2006, 05:03 AM   #36
zach007
Addicted Member
 
Join Date: Nov 05
Posts: 185
zach007 is an unknown quantity at this point (<10)
Re: ADO Beginners Tutorial

Hi,

What do you mean by that? Would you please provide "update" codes for everybody to learn..???
zach007 is offline  
Old Jan 9th, 2006, 07:46 AM   #37
si_the_geek
Super Moderator
 
si_the_geek's Avatar
 
Join Date: Jul 02
Location: Bristol, UK
Posts: 29,676
si_the_geek has a brilliant future (2000+)si_the_geek has a brilliant future (2000+)si_the_geek has a brilliant future (2000+)si_the_geek has a brilliant future (2000+)si_the_geek has a brilliant future (2000+)si_the_geek has a brilliant future (2000+)si_the_geek has a brilliant future (2000+)si_the_geek has a brilliant future (2000+)si_the_geek has a brilliant future (2000+)si_the_geek has a brilliant future (2000+)si_the_geek has a brilliant future (2000+)
Re: ADO Beginners Tutorial

For "update" just use the same code as cmdAdd_Click, but without the AddNew line.
si_the_geek is offline  
Old Jan 9th, 2006, 04:13 PM   #38
zach007
Addicted Member
 
Join Date: Nov 05
Posts: 185
zach007 is an unknown quantity at this point (<10)
Re: ADO Beginners Tutorial

VB Code:
  1. Private Sub cmdAdd_Click()
  2.     With rs
  3.         .AddNew 'adding new record
  4.         .Fields("field2") = Text1.Text 'setting field2 = whatever is typed in text1
  5.         .Fields("field3") = Text2.Text 'as above
  6.         .Fields("field1") = combo1.Text 'as above
  7.         .Update 'this updates the recordset etc.
  8.     End With
  9. End Sub

Hi, for "update" existing data....which code should I delete please..???

Thanks,

Jennifer
zach007 is offline  
Old Jan 9th, 2006, 05:10 PM   #39
si_the_geek
Super Moderator
 
si_the_geek's Avatar
 
Join Date: Jul 02
Location: Bristol, UK
Posts: 29,676
si_the_geek has a brilliant future (2000+)si_the_geek has a brilliant future (2000+)si_the_geek has a brilliant future (2000+)si_the_geek has a brilliant future (2000+)si_the_geek has a brilliant future (2000+)si_the_geek has a brilliant future (2000+)si_the_geek has a brilliant future (2000+)si_the_geek has a brilliant future (2000+)si_the_geek has a brilliant future (2000+)si_the_geek has a brilliant future (2000+)si_the_geek has a brilliant future (2000+)
Re: ADO Beginners Tutorial

Just remove:
VB Code:
  1. .AddNew 'adding new record
  2.  
si_the_geek is offline  
Old Jan 24th, 2006, 10:46 AM   #40
slaphead109
Member
 
Join Date: Oct 02
Posts: 54
slaphead109 is an unknown quantity at this point (<10)
Re: Database Password Protection

My database is password protected.

Where in the connection string is the password inserted please?
slaphead109 is offline  
Closed Thread

Go Back   VBForums > Visual Basic > Database Development


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 On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 08:07 PM.





Acceptable Use Policy

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.