Database Guide

Level:
Level2

This Visual Basic 6 guide walks you step by step through VB6 tutorials and VB6 source code on this site that will help you learn how to develop applications that store and retrieve data from database back ends. As you read each of these database tutorials you will gain more and more knowledge in how to handle databases in your VB apps. The best way to navigate through the guide is by using the links on the left. Or you can use the links below and then hit your browser's back button. Each link will take you to a different vb6 database tutorial on this site that will teach you the next step you need in order to become a VB6 database guru.

  1. To do anything of value in Visual Basic related to databases you will first need to learn how to write SQL statements to extract what you want from your back end database. This applies to not only Microsoft SQL server but also to Access and Oracle databases. Learn how with this Introduction to SQL (Structured Query Language)
  2. The data control in VB6 allows you to interact with your backend database with out having to write all the code by hand. This is great when you are first learning how to do database development in Visual Basic or for quick and simple VB6 database applications. For more complicated applications you will probably use ADO. Still check out this Database Access with the VB6 Data Control tutorial to start getting your feet wet.
  3. This tutorial is optional as DAO is a somewhat older way of Visual Basic database development. However, if you ever have to interact with older code its good to at least understand the basics of this. Check out the Using DAO (Data Access Objects) Code Tutorial
  4. Again, RDO is still not the newest (and best) way to access back end data. However, there is a lot of VB database code out there that uses RDO so its probably good to at least glance through this tutorial in order to know what to do if you ever work on and VB RDO project. Database Access with RDO (Remote Data Objects) in VB6
  5. This is a must read! Visual Basic ADO development is the newest (and best) way to interact with any database. After walking through this tutorial you should be able to have every tool in your belt to grab data, modify it, and write back to any database you come in contact with. Any VB6 database developer must read this Database Access With ADO in VB6 tutorial
  6. Once you understand all the basics of how to use ADO to work with a database you will probably want to display that data to your end user in some way. One very effective way of doing this is with the list view that is built into the VB6 IDE. Using ADO and the ListView control in VB6
  7. It is bad programming practices to write all your SQL statments directly into your Visual Basic source code. This makes it hard to change things down the road and also has a performance disadvantage compared to using stored procedures. Learn how all this works in this tutorial: Using ADO and stored procedures in VB6
  8. If you ever need to print of reports for end users you might want to consider using Crystal Reports. Although many times you can get away with writing your own reports or exporting things to Excel or Word at times this isn't an option. Check out this Using Crystal Reports with VB6 tutorial to learn more about how to create these for your end users.
  9. Optional: This is optional because unless you are having to interact with an Oracle database you will never need to know this information. However if there is a time you need to use Visual Basic and Oracle together I recommend you check out this
  10. If you enjoyed this post, subscribe for updates (it's free)

Public con As New

Public con As New ADODB.Connection 'code for login ad reference ms ado2.0 library

Public rs As New ADODB.Recordset
Public rno As Integer

Private Sub LOGIN_Click()
rs.Requery
Dim flag As Integer
flag = 0
Do While Not rs.EOF
If USERNAME.Text = rs.Fields(0) And PASSWORD.Text = rs.Fields(1) Then
flag = 1
rno = rs.AbsolutePosition
If rs.Fields(2) <> "administrator" Then
form2.create.Visible = False
End If
con.Close
form2.Show
FORM1.Hide
Exit Do
Else
rs.MoveNext
End If
Loop
If flag = 0 Then
PASSWORD.Text = ""
invalid.Caption = "INVALID USER NAME OR PASSWORD"
invalid.Visible = True
PASSWORD.SetFocus
End If

End Sub

Private Sub Form_Load()
invalid.Visible = False
Label1.Caption = "user name"
USERNAME.Text = ""
Label2.Caption = "password"
PASSWORD.Text = ""
LOGIN.Caption = "LOGIN"
con.Open ("PROVIDER=SQLOLEDB.1;DATASOURCE=MUZAFAR-A2A9EE7;INTEGRATED SECURITY=SSPI;INITIAL CATALOG=HRMS")
rs.Open "SELECT * FROM USERID", con, adOpenStatic, adLockOptimistic
End Sub

Public con As New

Public con As New ADODB.Connection
Public rs As New ADODB.Recordset
Public rno As Integer

Private Sub LOGIN_Click()
rs.Requery
Dim flag As Integer
flag = 0
Do While Not rs.EOF
If USERNAME.Text = rs.Fields(0) And PASSWORD.Text = rs.Fields(1) Then
flag = 1
rno = rs.AbsolutePosition
If rs.Fields(2) <> "administrator" Then
form2.create.Visible = False
End If
con.Close
form2.Show
FORM1.Hide
Exit Do
Else
rs.MoveNext
End If
Loop
If flag = 0 Then
PASSWORD.Text = ""
invalid.Caption = "INVALID USER NAME OR PASSWORD"
invalid.Visible = True
PASSWORD.SetFocus
End If

End Sub

Private Sub Form_Load()
invalid.Visible = False
Label1.Caption = "user name"
USERNAME.Text = ""
Label2.Caption = "password"
PASSWORD.Text = ""
LOGIN.Caption = "LOGIN"
con.Open ("PROVIDER=SQLOLEDB.1;DATASOURCE=MUZAFAR-A2A9EE7;INTEGRATED SECURITY=SSPI;INITIAL CATALOG=HRMS")
rs.Open "SELECT * FROM USERID", con, adOpenStatic, adLockOptimistic
End Sub

How to store image path to a database using vb6

Sir/Ma'am,

Need your expertise...i want to know how to save the image path of the pictures to a database...so that every time i select a record in a grid the data will appear in textboxes including the picture in the image control...thnx more power!!!

cool

it is a basic thing . You should learn more .

airline reservation system project code

SIR..I AM A STUDENT .im frm 3RD YR B.C.A . I WANT TO DO A PROJECT ON AIRLINE RESERVATION SYSTEM.PLEASE HELP ME WITH THE CODE AND FORM DESIGN,USING VB 6 AS FRONT END AND ORACLE AS BACK END. IT IS TO BE DONE WITH ADODC CONNECTIVITY,,,SIR PLEASE DO HELP ME....PLEASE...
DO SENT IT TO ME IN veena_ban123@yahoo.co.in

airline reservation project in vb 6.0

Sir, I am student of final yr B.E..I want to do a project on airline reservation in vb6.0..Please help me with the code and form design using vb6.0 as front end and MS Office as back end..With ADODC Connectivity...Sir Please help me And do sent me on snehadhundale@gmail.com..

Picture reporting

Joseph

Plz i need the code to report picture that was stored in my database (ms access) i want to report the picture to a form

reply plzzzzzzzzz

thankz

how to save the values daily using ADODB with corresponding date

i want to make a project for storing the records of patients.so to update them daily,i need the date to be displayed automatically.so please sir provide me the tips and source code for this.this is urgent to me .

vb with database

i need to connect vb with MS-access

To connect Ms-Access

To connect Ms-Access with VB6.0, just follow the below steps.,

1. Go to the Project -> Select Microsoft DAO 6.0 Object Library (for Ms Access 2000 or above) or 3.51 Microsoft DAO Object Library (for lower versions).

2. Go to code view, declare a variable
Dim DbConn as DAO.Database

3. Write the below code in Form_Load
DbConn.opendatabase("Exact path or the location of the database")
If you secured your database with password then use this
DbConn.opendatabase("Exact path or the location of the database", false, false, ";pwd=password")

4. Now, your connection with Access is established. Use the DbConn to execute query strings or query defs.

If you want to make the connection as global, establish connection with database in module by declaring the database as public.

You can use ADODC to connect

You can use ADODC to connect your database with your vb. Just add component with your tools and check ADO data controls and then OK..
Check the properties of your ADODC by setting the path of your ms access..

please give more details

please give more details

complete codes

help me to make a program please give me a complete sql commands in add, edit,view,search,
in visual basic 6

visual basic connectivity

hi,
i am a new user of vb6.0 i have placed an adodc object in the form and made a connection (access database) with the ODBC in administrative tools.
i can able to view the records but i am in need of add, delete and update a record through vb coding by simply clicking those respevtive buttons.
please give the code as soon as possible.

hi help me please

im writing this code for finding out capacity of a pump. though it is a simple code, but it creats an error not divisible by zero (error 11) plz help me for correcting error. here im attaching my total code, plz go through once.

Private Sub cmdCalculate_Click()
Dim Discharge As Single
Dim Head As Single
Dim Pumpefficiency As Single
Dim Motorefficiency As Single
Dim Driveefficiency As Single
Dim Whp As Single
Dim Shp As Single
Dim Bhp As Single
Dim KW As Single

On Error GoTo ErrorMessage

'Read values from text boxes
Discharge = Val(txtDischarge.Text)
Head = Val(txtHead.Text)
Driveefficiency = Val(txtDriveefficiency.Text)
Pumpefficiency = Val(txtpumpefficiency.Text)
Motorefficiency = Val(txtmotorefficiency.Text)
Whp = (Discharge * Head) / 76
Shp = (Whp * 100) / np
Bhp = (Shp * 100) / Driveefficiency
KW = (Bhp * 0.746 * 100) / Motorefficiency
'Compute final value and put in text box
txtWhp.Text = Str(Whp)
txtShp.Text = Str(Shp)
txtBhp.Text = Str(Bhp)
txtKW.Text = Str(KW)

Exit Sub

ErrorMessage:
If Err.Number = 5 Then
MsgBox ("Negative discriminant : Re-enter input data")
ElseIf (Err.Number = 6 Or Err.Number = 11) Then
MsgBox ("Division by zero : Re-enter input data")
End If
Resume ClearInput

ClearInput:
textDischarge.Text = ""
textHead.Text = ""
textDriveefficiency.Text = ""
txtpumpefficiency.Text = ""
txtmotorefficiency.Text = ""

End Sub
Private Sub cmdExit_Click()
End
End Sub
Private Sub cmdClear_Click()
txtDischarge.Text = ""
txtHead.Text = ""
txtDriveefficiency.Text = ""
txtpumpefficiency.Text = ""
txtmotorefficiency.Text = ""
txtWhp.Text = ""
txtShp.Text = ""
txtBhp.Text = ""
txtKW.Text = ""

End Sub

Shp = (Whp * 100) / np From

Shp = (Whp * 100) / np

From the above, what is np?
It is not declared and assigned.

About that codding part

Dude if i want to correct this codding part. i want to check the design part also . if u want any help from me . just sent a mail ok .
by, arun prakash.c

hi,am stuck with a problem

hi,am stuck with a problem as to hw to insert values to database(mysql),thru vb form,cn u plz give me the code to do it?
plzzzzzzzzzzzzzzzz.........help.....

Want ur help

I doing project on pilot auto Ltd.
I want to know how to connect access database in vb6?
how to bind data to datagrid,combo box?
and how to fire query to database such as "select * from pilotlog;"

w3w

im still a newbie, but i know little

ahm you can connect database access by means of hard coding or there is simple one..

the simpler one:
1. find microsoft ADO data control 6.0 (OLEDB)
2. create one adodc object on the form
3. right click the object
4. then go to adodc properties
5. hit build, another prompt up window will show up
6. choose microsoft jet 4.0 OLE DB provider, then
7. find your databse by clicking the browse button, then hit ok
8. go to recordsource tab
9. from the command type, choose 2- adcmd table, and the table name, then click ok
10. on the textbox properties find datasource
11. choose adodc1, then
12. find datafield, choose the table
13. run the program

for the hardcoding:

1. find microsoft ADO data control 6.0 (OLEDB)
2. create one adodc object on the form
3. right click the object
4. then go to adodc properties
5. hit build, another prompt up window will show up
6. choose microsoft jet 4.0 OLE DB provider, then
7. find your databse by clicking the browse button, then hit ok
8. copy the provider on the build box ex. "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Program Files\Microsoft Visual Studio\VB98\BIBLIO.MDB;Persist Security Info=False"
9. paste it to your code like: and change it to:

Private Sub Form_Load()
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\BIBLIO.MDB;Persist Security Info=False"

text1.text = adodc1.recordset!fields("fieldname")
End Sub
10. run the program

pars-programmed airline reservation system

IS there a way to access on line PARS to see airlines availability?

saving data of checkbox in a table

sir
can u help me in saving data from checkboxes to my access database

How to display data from SQL to textbox in vb 6.0

Hi Every1,

I want to display data from my SQL database to vb front end in textbox.
how m i to retrive data n display it.

I m a trainee, plz help.

dispaly text from database

Private Sub Select_Click()
Dim Cmd As String
'con.Open ("focus6")
If rs.State = 1 Then rs.Close
Cmd = "select * From employe where id=" & txtid.Text
rs.Open Cmd, con, adOpenDynamic, adLockOptimistic
If rs.EOF = False Then
txtname.Text = rs!Name
txtage.Text = rs!Age

End If

how to open vb6 form in msword for r

hi sir, my problem is that, how to open vb6 form in msword for printing a form.

just run that form and press

just run that form and press Alt+print_screen button from keyboard.
now open a word document and paste it or press ctrl+v.
you will get your form in word and then u can take printout.

check field in database before inserting

im inserting values in a access database using sql query...... and im in a state where i need to first check wether the value im inserting exist earlier in the database... the point is that tabl cant have primary key and the field is in text format. can anyone give any type of solution as soon as possible... my mail id is => sumeetpardeshi@sify.com

visual basic

hai i got a problem that how to give the connection through combobox to oracle database

adodc

how to compare an item listed in combo box with the item(text type) in the database adodc.

vb

i have a airline reservation code in vb, i would like to make it online. please help me on how to do this

dynamic data from database

Hello
can i fetch data dynamic from excel file in VB .the data should be in same format as in excel.and display that data on front end
any rply should b appreciated

thank you

Fetching data from Excel

Use Datagrid.
Make sure that the header in the excel will be same as the datagrid headers.

fetch

using rs u can do this

Remote Connection string for VB6 connecting Access

Hi Everyone,

I have an Access 2007 Database in Server & I need to connect from client using VB6. I need connection string for this. My Access database is residing in server C:\Program Files\DBfolder.

Thanks in advance
naz

CODE

Private Sub Form_Load()
With con
.Provider = "Microsoft.jet.oledb.4.0"
.ConnectionString = "c:\computer.mdb"
.Open
End With
With rec
.Open "Table1", con, adOpenKeyset, adLockOptimistic
End With
If rec.RecordCount > 0 Then
Call disprec
End If
nrec = False

End Sub

hi!

want to know what connection string is right for your program? i found a site that might help u! visit http://www.connectionstrings.com/

RE: Remote Connection string for VB6 connecting Access

Hi naz!

Here's what you gonna do (LAN).

1.) Shared the folder(DBfolder) of your db. Here's how:
Goto C:\Program Files
Right-click the DBfolder then 'Properties'
Click the 'Sharing' tab
Click the 'Share this folder' radio button
Click the 'Apply' button and 'OK'

2.) Get the ip address of your DB Server. Here's how:
Click 'Start'
Click 'Run'
Type 'cmd' and hit enter
On console type 'ipconfig'
Then write on a peace of paper the IP Address (e.g 172.16.0.1)

3.) On your client pc try to connect to the shared folder of your server. Here's how:
Click 'Start'
Click 'Run'
Type your server ip (e.g \\172.16.0.1) and hit enter
New window will appear (172.16.0.1) then you'll see the folder named DBfolder

4.) Lastly. Create your DSN-less connection string
Provider=Microsoft.Jet.OLEDB.4.0; Data Source=\\172.16.0.1\DBfolder\yourdbname.mdb

I hope this can help.

tobz

vb6 code " & App.Path & " \

vb6 code

" & App.Path & " \ DBFolderName\DBName

or if you want String

Declare

Private Const dbPath As String " \ DBFolderName\DBName "

Save data linke to another table

sir i am a beginner of vb 6.0 and i would like to ask for your help..i have 2 tables table A and table B. these table is link through ID. In my second form i have a combo box which i populated it with the Names from table A. How can i save the other data to table B in such a way that those data i save will be under that particular Name i choose in the combo box
so after i choose Name in the combobox i will supply data to the textboxes in that form like the place and address..so when i click save i want that the details like the place and the address i put in the textbox will be save in table B under that particular name i choose in the combo box im using adodb..Thank you..

All

How to Sample Program Using DataBase In VB6.0
Thanks!!

Compare Input with Original Database...

I have some textbox to enter data.i want to check the entiring value is similar to a record or not.how can i do?please help...

Ask

What is your backend(database)?

heeloo..

can you me help 'bout menu editor code? please.......

HI

You got know already about menu Editor?
Use your Simple code to open other form.

ppl help me out

ppl help me out plzzzzz.....
i need vb 6.0 software fr ma prjct...

i have it.whr r u?

i have it.whr r u?

VB 6.0 s/w domnload???

Can anyone suggest the site to download VB s/w

vb

guide line

ENGLISH! Y'speak it?!?

ENGLISH! Y'speak it?!?

ADO and Winsock

Hi to all,

can you help me to create a program which is using an ADO Database via winsock?

thanks

sql statement problems

using sql statements, i can access my database, but there some problems i dont really know what to do..
help me please with these...

i tried to execute the following.
update table_name
set field_name = txt_field.text
where field_name = txt_field.text

the error was: data type mismatch.
the thing is i know what the error means, but it was nonsense, cause im sure im right about my data types
and when i try to cut condition in my sql statement, it successfully run....

then....
delete from table_name where field_name = txt_field.text
the thing is that it successfully run but npthing happen, no errors.
please help me with these.

im a student, and trying study well, please help me with these..

thanks..

Using Access Database Having Password

hi,
i can use access database without password from vb 6.0 but i can't use access database having password, and it shows error. so if any can solve this problem please reply me.

Access DB with password

dnesh take a look at this example:

Option Explicit

Public ConnDB As ADODB.Connection

Public Sub ConnectDB()
'Check if ConnDB is already been instantiated if not then do the instantiation
If ConnDB Is Nothing Then Set ConnDB = New ADODB.Connection

With ConnDB
.CursorLocation = adUseClient
.Open "Provider=Microsoft.Jet.OLEDB.4.0; Persist Security Info=False; Data Source=C:\TestDB.mdb; Jet OLEDB:Database Password=dbpassword"
End With
End Sub

I hope this can help.

tobz

Help me for my project

i need source code in VB for the meter polling procedure for the outage restoration in electrical distribution system...am not getting properly..it need urgently

hello

pls help me for making project(collage management) by taking backend and frontend in visual basic

addnew comment(dao) in vb6 using coding

i Want to add new records in access database using coding in vb6

Check this out!!!!

This is just an example try to implement this idea.Ok?

......................Private Sub cmdadd_Click()................
rs.AddNew
txtNo.Text = ""
txtName.Text = ""
txtCity.Text = ""
txtDob.Text = ""
txtPhone.Text = ""
txtprovince.Text = ""
txtzip.Text = ""
txtstatus.Text = ""
txtrate.Text = ""
End Sub
............Private Sub cmdsave_Click()................
rs(0) = txtNo.Text
rs(1) = txtName.Text
rs(2) = txtCity.Text
rs(4) = txtDob.Text
rs(3) = txtPhone.Text
rs(5) = txtprovince.Text
rs(8) = txtzip.Text
rs(6) = txtstatus.Text
rs(7) = txtrate.Text
rs.Update
MsgBox "The record has been saved successfully.", , "Human Resource"
End Sub

Adding new record in vb6

Private Sub cmdadd_Click()
'NB: Use what is contained in your databse;the fields txtno,txtname are mine use what is in your 'application. Am hoping that you have already linked your application to tha database.
rs.AddNew
txtNo.Text = ""
txtName.Text = ""
txtCity.Text = ""
txtDob.Text = ""
txtPhone.Text = ""
txtprovince.Text = ""
txtzip.Text = ""
txtstatus.Text = ""
txtrate.Text = ""
End Sub
Private Sub cmdsave_Click()
rs(0) = txtNo.Text
rs(1) = txtName.Text
rs(2) = txtCity.Text
rs(4) = txtDob.Text
rs(3) = txtPhone.Text
rs(5) = txtprovince.Text
rs(8) = txtzip.Text
rs(6) = txtstatus.Text
rs(7) = txtrate.Text
rs.Update
MsgBox "The record has been saved successfully.", , "Human Resource"
End Sub

excellent set of steps... is

excellent set of steps... is a very impressive and useful resource

how to show the database of

how to show the database of mysql in vb6 ................. how to query ??? i need its coding can u plz help me out with it

Inquiry

Hello there!

May ask how to make database using MySQL as a backend and Visual Basic 6.0 as frontend?
Need help on this.

Thanks.

Kind regards,
Rey

airline reservation system project code

SIR..I AM A STUDENT IN 12TH. I WANT TO DO A PROJECT ON AIRLINE RESERVATION SYSTEM.PLEASE HELP ME WITH THE CODE AND FORM DESIGN,USING VB AS FRONT END AND ORACLE AS BACK END. IT IS TO BE DONE WITH ADODC CONNECTIVITY,,,SIR PLEASE DO HELP ME....PLEASE...
DO SENT IT TO ME IN rinieliza_1392@yahoo.co.in

Use of Data Grid as Input for an Invoicing System

Dear Sir,

I am a new member of the site of VB6. It is a very usefull site. I have learnt a lot from this site. As concerned to my problem, it is that i want to use Data Grid for capturing a Sales Invoice Entries. How do i can use Data Grid as for Data input and also tell how can I validate the fields of Data Grid, while using it as Data Entry tool.
If it is not possible to use Data Grid as data entry tool , please guide me to some other way to capture a Sales Invoice entries.

Thanking You

Regards

6Nazakat

how can i make a data base w/ log in function ??

how can i make a data base w/ log in function ??
i want to pass this project into the accounting office of our school for additional grade ..
please help me about this matter ..
im a second year college student and 18 years of age ..
thanks a lot .. hoping to be guided ..
-- just asking ..

how to add data to access database using adodc

i have connected my adodc to my vb,but when i add a new record, it deletes the previews record.i need urgent help

what is your code?

post your code here so we may help you :)

help me

dim z as integer

if adodc1.recordset.recordcount > 0 then
z=z+1
z=txttransID.text
else
z=1
end if
.....................................
what is the right code in order to add the ID to 1 ?and at the same time it can add even the record is = to empty.

code for edit in vb6 to be linked to MS Access

what is the EDIT code for vb 6 to be linked to MS Access? pls.. help.. tnx.. i just need the code for edit.. here's my code for add and delete:
Private Sub cmdAdd_Click()
Call Open_Conn
If cmdAdd.Value = True Then
cn.Execute "Insert into table1 values(' " & Trim(Text1.Text) + " ',' " + Trim(Text2.Text) + " ')"
MsgBox "New Record Saved!", vbInformation, "Added"
Call Close_Conn
Else
MsgBox "No current record", vbInformation, "Error"
End If
Text1.Text = ""
Text2.Text = ""
End Sub

Private Sub cmdDel_Click()
Call Open_Conn
cn.Execute "Delete from Table1 where Name=(' " & Trim(Text1.Text) + " ')"
MsgBox "Record deleted!", vbInformation, "Info"
Call Close_Conn
Text1.Text = ""
Text2.Text = ""
End Sub

Database SQL Queary

I Create a Student database. Now i want to Search any fields and i want to use SQL Code. I use Access Database. How can make SQL Builder Form? Than How can Print my Form? Please send same Project and code. This Email: zubair_312@yahoo.com

Print code

I want to print code. Because i cannot print my form.