please Need Help With Vb6 And Databases

A Member? Please Login  
type your username and password to login
Date: October 14, 2008, 01:33 PM
249766 members and 148452 Topics
Latest Member: happinessa
Nairaland [Nigerian Forum] Home Help Search Who is currently online? Login Register
Nairaland Forum  |  Technology  |  Programming  |  please Need Help With Vb6 And Databases
Pages: (1) Go Down Send this topic Notify of replies
Author Topic: please Need Help With Vb6 And Databases  (Read 484 views)
sallyjabz (f)
please Need Help With Vb6 And Databases
« on: January 17, 2007, 01:50 PM »

 :)please need help with connecting vb6 forms using microsoft acess database including codes for adding,saving,deleting,updating etc records
dag (m)
Re: Please Need Help With Vb6 And Databases
« #1 on: January 17, 2007, 02:54 PM »

u have to be specific though, but i think ur connecting via the wrong engine and maybe the wrong object. try this:

connect to access using the ADO Object, to use it you must add a refrence to it from the project menu

use the microsoft jet 4.1 engine to connect to access

to ensure update operations on ur recorset you must use Optimistic setting via the advanced tab on the dialogue box that shows you the ADO prefferences.

note ADO internal algorithm for CRUDE operation is not very reliable, using SQL performs better but requires learning the syntax, but it will scale well for small applications. also make sure your running on the correct OS earlier versions of windows 98 do not fully support the ADO object effectively.
if ur more specific ill tell u exactly what to do to get u up and runing with access
Shimao (m)
Re: Please Need Help With Vb6 And Databases
« #2 on: January 17, 2007, 05:56 PM »

hello,
i'll briefly explain how you can do that.
since you want to use acces,i expect that the database is ready for connection and has been copied into your project folder.
the first thing to do is to create your data-bound controls on the form,these are the control:labels,textboxes that will bear the output from the database.
the actual connection to the database can be done in two ways-
using the ADO data control:an activeX control or using a Data enviroment.
i'll explain that of the ADO as it is easier to grasp and you wont need to do much coding.
go to an empty space on the toolbox, right click and select "components".
then from the dialog box that shows a list of controls,check the one for Ms ADO control or so.then ok.
this action brings the ADO control into your toolbox and ready for use.
get the control unto your form you'll see a control with 2 left arrows, 2 right arrows and a central textbox(navigation buttons) ,resize,position and rename app'ately.
right click on the control on your form and go to "properties".
find your way to "connection build" command button and specify  the database engine to be used,for access it's microsoft jet engine 4.1, the path to the database afterwards, click on test connection to test the integrity of the link.if you get a successful response then you're almost done.
then find you way to the recordSource tab and specify what kind of let-say database.i suspect you'll be usint a table so pick on adcmdTable-if i got it right then exit the dialog box,
back to your form,for each data-control you'll be using,go to the properties bar and click on "data source",in the drop down menu select your ADO(should be the only one).
then go to the "data field" and specify the column-the field the control would bear from the dropdown list showing all the available feilds.do this for the remaning data-controls and run your form.
automatically,the first entry of the database is displayed and you can navigate through the rest using the ADO control.thats all.
NB.i suggest you use labels as the data contained in the database can be modified from the form,so for the first time avoid using textboxes or set their locked property to true.
i leave you to discover some other things yourself.
so you see you do not need any code to display the data,however if you'll want to use command buttons to navigate,you'll have to set the visibility of the ado control to alse and manually code the movements.
the other using the data enviroment is more complex as you'll have to code for the all the actions however i think it;s better.
i hope i've tried,the details might not be pinpoint as i or you have wanted it to be,but i believe,i've given you the idea and you should be able to find your way.forgive me for whatsoever errors their may be.happay coding
dejisys (m)
Re: Please Need Help With Vb6 And Databases
« #3 on: January 17, 2007, 07:49 PM »

Get a gooood VB book. Thats the best advice you can get. If you have a specific problem, then you can post it in a forum like this.
adewaleafolabi (m)
Re: Please Need Help With Vb6 And Databases
« #4 on: January 17, 2007, 09:52 PM »

vb 6 doesn't work with databases created with office 2003 upwards. so its very possible that sally might be using this version and whatever database created wouldn't work
Fdeveloper (m)
Re: Please Need Help With Vb6 And Databases
« #5 on: January 18, 2007, 09:58 AM »

Just a quick question, is there any particular reason why you are using VB6 and not .NET?
parosky (m)
Re: Please Need Help With Vb6 And Databases
« #6 on: January 18, 2007, 10:51 AM »

@adewaleafolabi
That is not true. VB6 connects to any database, any access db. The problem may be that you specified the wrong jet engine in your connection string. Access 2003 uses jet 4.1 as against 3.1 and I think 2.5 of earlier versions.

Shimao has done a good job connecting you with ADO control. But if you are a serious developer and want greater flexibility, learn to code directly against the ADO object. Ask if you want to know more or get a book.

Also retrieve your records using sql Update, Insert, Select and Delete commands. It's a lot better.
sallyjabz (f)
Re: Please Need Help With Vb6 And Databases
« #7 on: January 18, 2007, 12:18 PM »

thanks guys 4 all ur contributions but i ve tried all jet engines and i even tried converting the acess database formats to earlier versions like 1997 which worked  only with the DAO data object and the applicaton/program was working fine and i was able to add,delete,update,save records using the vb codes for recordsets on their respective command buttons. The main problem i had was when i packaged and deployed the application to another system i was having problem with the connection with access even though d  the database itself exist on the system.

ADO
As for ado i have connected already with both with connection string using adoc properties and also the data environment.The problem i have with ado is that even after i put the codes in the respective command buttons it doesn't work unlike DAO which worked

dag and parosky suggested i use SQL .but i thought it's mainly used for generating reports.but if there's any way help can be rendered i will be very grateful.
            I have read most books as u all know some topics are usually briefly treated
shimao thanks 4 ur help and fdeveloper i do program with VB.NET but ve not tried connecting it to a database may be u can be of help with .NET
AND LASTLY
THANKS!
parosky (m)
Re: Please Need Help With Vb6 And Databases
« #8 on: January 18, 2007, 12:52 PM »

Don't worry it will work

1. Drop an Adodc on a form
2.Click the ellipsis next to the ConnectionString property in the ADO Data Control’s Properties window to bring up the Property Page dialog box for this property
3. On the page that opens, select "Use ConnectionString" then click the Build button to bring up
the Data Link Properties tabbed dialog box.
4. On the Provider tab of the Data Link Properties tabbed dialog box, choose an OLE DB data provider, such as Microsoft Jet 3.51 OLE DB (for office 2000) depending on which version of office you are using. If you have office 2003 you'll choose Microsoft Jet 4.1 OLE DB.
5. Then click  OK
6. Then on the Connection tab select the path to your access db and click on a button "Test Connection". It should tell you that  you are successful.
I assume you know how to bind your controls to a Adodc, which you should now do.

Let us know how far.
sallyjabz (f)
Re: Please Need Help With Vb6 And Databases
« #9 on: January 18, 2007, 03:32 PM »

parosky thanks 4 ur reply but i have tried all that and what i need is how 2 update,delete add,save the records in d database via it's interface in vb6 using Adoc properties.What are d codes 4 their respective command buttons.i have been able 2 move to d next record,previous record e.t.c All these have been sucessful with DAO but i just want 2 try it with ADO
parosky (m)
Re: Please Need Help With Vb6 And Databases
« #10 on: January 18, 2007, 05:09 PM »

Your recordset object has a delete, AddNew, Update methods for you to use. Find out about them

Private sub SaveData
  myRs.Addnew                              'to be called  to add a new record
  LoadDataIntoRecordset               'your routine to update copy buffer
  myRs.Update
end sub

Private Sub DeleteEntry
  myRs.Delete
  myRs.MoveNext
End Sub

Need more explanation?
sallyjabz (f)
Re: Please Need Help With Vb6 And Databases
« #11 on: January 19, 2007, 11:48 AM »

parosky thanks a lot i think i'm on track
parosky (m)
Re: Please Need Help With Vb6 And Databases
« #12 on: January 19, 2007, 02:30 PM »

Yes you are on track now. But learn to use sql to interact with your database. Thats the gold standard.
dag (m)
Re: Please Need Help With Vb6 And Databases
« #13 on: January 20, 2007, 11:16 AM »

good to see ur on track, but you need to learn how to create robust code and remember like i said the ADO object methods throws a lot of unhandled error that you'll have to account for, try and add the following bold statements to paroski's code to handle generic exceptions.

sub AddNewItem
    On Error Resume Next
    myrs.addnew
    'perform add operations here
    myrs.update
end sub

on ur development environment make sure the database file is copied to a path that is identical to the path you used for development. it is better you create ur datadabe file directly in the C:\ directory, since the mydocument user name varies for different system, using that same path would generate connections errors since the user of the developmet machine might be using i diff name thus affecting the folder. a more proffessional way is to script the deployment of the access database.
parosky (m)
Re: Please Need Help With Vb6 And Databases
« #14 on: January 20, 2007, 12:27 PM »

@dag
How far? Good to see your contribution.

On error resume next may not be too good. On Error GoTo is better so that known errors can be handled in a magnificient way. some thing like

sub AddNewItem
    On Error GoTo AddNewItemError

    myrs.addnew
    'perform add operations here
    myrs.update

exit sub

AddNewItemError:
set myRs = nothing
msgbox err.Description & ". An error occured. Item not yet added"     ' a user friendly error message

end sub
dag (m)
Re: Please Need Help With Vb6 And Databases
« #15 on: January 22, 2007, 07:30 PM »

hey paroski, good looking over my shoulder, i intentionally did that didnt wanted to crowd our good friend with all them exception syntax, i really did expect u to comment on that code snippet though. interesting how u set the recordset object to nothing thus releasing its consumed resources.

and to sylyjab its good thing you get your feet wet with the database object using ado on vb6.0, though .Net uses a different paradigm it still builds on the basics of legacy Ado, so don't listen to people that'l tell u its a waste of time using vb6.0. there is a tool called the data environment designer on vb6.0 great tool for manipulating recordsets, similar to the way ado.net does. you could google it to get ur hands on.
KESKAR
Re: Please Need Help With Vb6 And Databases
« #16 on: February 23, 2007, 10:15 PM »

try this  syntax:
rsecordset.Open "select * from, "  connetion_name, adOpenDynamic,adLockOptimistic
  Oracle Tutorials  Algorithm For Solving Systems Of Linear Equations  Sir What Is Different Between Programmer And Non-programmer?  Page 2
Pages: (1) Go Up Send Topic to Friend by E-mail Reply 
Google
 
Web www.nairaland.com
Sections: TV/Movies (2) Music/Radio (2) Celebrities Job Talk Jobs/Vacancies (2) Career Talk Romance Books Politics Sports Fashion Travel
Health Schooling Religion General(2) Business Webmaster Programming Computers Phones Cars & Trucks

Links: Page1 Page2 Page3 Page4 Page5 Page6 Page7 Page8 Page9 Page10

Nairaland is owned by Oluwaseun Osewa
Nairaland Forum | Powered by SMF 1.0.12.
© 2001-2005, Lewis Media. All Rights Reserved.