Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,150,395 members, 7,808,390 topics. Date: Thursday, 25 April 2024 at 11:22 AM

Pls Need Help With Vb6 And Databases - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Pls Need Help With Vb6 And Databases (2000 Views)

Login Code In Vb6.0 / Printing With Vb6 / Help me convert this Vb6.0 code To Vb.net (2) (3) (4)

(1) (Reply) (Go Down)

Pls Need Help With Vb6 And Databases by sallyjabz(f): 1:50pm On Jan 17, 2007
smileypls need help with connecting vb6 forms using microsoft acess database including codes for adding,saving,deleting,updating etc records
Re: Pls Need Help With Vb6 And Databases by dag(m): 2:54pm On Jan 17, 2007
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
Re: Pls Need Help With Vb6 And Databases by Shimao(m): 5:56pm On Jan 17, 2007
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 belive,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
Re: Pls Need Help With Vb6 And Databases by dejisys(m): 7:49pm On Jan 17, 2007
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.
Re: Pls Need Help With Vb6 And Databases by adewaleafolabi(m): 9:52pm On Jan 17, 2007
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
Re: Pls Need Help With Vb6 And Databases by Fdeveloper(m): 9:58am On Jan 18, 2007
Just a quick question, is there any particular reason why you are using VB6 and not .NET?
Re: Pls Need Help With Vb6 And Databases by parosky(m): 10:51am On Jan 18, 2007
@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.
Re: Pls Need Help With Vb6 And Databases by sallyjabz(f): 12:18pm On Jan 18, 2007
thanks guyz 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!
Re: Pls Need Help With Vb6 And Databases by parosky(m): 12:52pm On Jan 18, 2007
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.
Re: Pls Need Help With Vb6 And Databases by sallyjabz(f): 3:32pm On Jan 18, 2007
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
Re: Pls Need Help With Vb6 And Databases by parosky(m): 5:09pm On Jan 18, 2007
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?
Re: Pls Need Help With Vb6 And Databases by sallyjabz(f): 11:48am On Jan 19, 2007
parosky thanks a lot i think i'm on track
Re: Pls Need Help With Vb6 And Databases by parosky(m): 2:30pm On Jan 19, 2007
Yes you are on track now. But learn to use sql to interact with your database. Thats the gold standard.
Re: Pls Need Help With Vb6 And Databases by dag(m): 11:16am On Jan 20, 2007
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.
Re: Pls Need Help With Vb6 And Databases by parosky(m): 12:27pm On Jan 20, 2007
@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
Re: Pls Need Help With Vb6 And Databases by dag(m): 7:30pm On Jan 22, 2007
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 dont 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.
Re: Pls Need Help With Vb6 And Databases by KESKAR: 10:15pm On Feb 23, 2007
try this syntax:
rsecordset.Open "select * from, " connetion_name, adOpenDynamic,adLockOptimistic

(1) (Reply)

Learning / Asp.net GRIDVIEW ERROR Using Vb.net / 17-year-old Boy Sells App For $30 Million To Yahoo Inc

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 42
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.