How to connect with DB(Database)
For beginners, we will take database as access database for understand simple project, how to connect acess database with simple saving method.

Step_1 : make a simple access file with name XYZ, and make table name Cname, there we will make only two field. first field name we choose C_Name and second for address. save in D:/ drive, its not important you save the file in D:/ drive, important is you have to give path of saved database in code.
save access file and come on visual basic plateform, now open new project select two text box and draw with proper label as we learned before. now we will enter the code for connection

See right side picture there is used controls are lables, textboxes and command buttons. draw label name to navigate fields, make textboxes blank.
Label captions, textboxes modify by control properties, which is disply on right side of program windows, as we see in let topic , right side three windows will be opened in defult setting,
first will be project explorer, in project explorer you can see and add-remove form, project, module, class module etc... it is naviagator of project, simple image its like a windows explorer which you can see all windows sitmap.
second windows will be desply in defult setting is control properties, you can see the picture, there is i made some colourfull label through control properties.
third will be form layout window, this tool is very usefull for child form setting, mostly usefull for alignment of child form, we will discuss on this tool later.
Now, lets see which coding will be used for this project.
first declare connection, but remember that delcaration only on top of the coding windows, you can identify your declared code is on top of the coding windwos through to two combo boxes in first should be appear (general) and second combo should for declarations),
now type as below:
Dim CN as new connection
Dim RS as new recordset
-----------------------------------------------------------------------------------
Now type code for command windows, just double click on command button, code windwos will be disply against you just type as below, but remember that might when you click on command button, if your command button name is not changed you can see the code like
private sub commandbutton1_click()
end sub
-- but here i modified name as cmdclick OK! now type the code between both lines as below.
Private Sub cmdclick_Click()
Set CN = New ADODB.Connection
Set RS = New Recordset
CN.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\xyz.mdb;"
If TextBox1.Text = "" Then
MsgBox "Please Enter Customer's Name.", vbInformation, "INFORMATION"
TextBox1.SetFocus
ElseIf TextBox2.Text = "" Then
MsgBox "Please Enter Customer's Address.", vbInformation, "INFORMATION"
TextBox2.SetFocus
End If
RS.Open "select * from Cname", CN, adOpenKeyset, adLockPessimistic
If RS.EOF = False Then
RS.AddNew
RS(1).Value = TextBox1.Value
RS(2).Value = TextBox2.Value
RS.Update
RS.Close
End If
CN.Close
TextBox1.SetFocus
TextBox1.Text = ""
TextBox2.Text = ""
End Sub
------------------------------------
Now, run project and enter data, result you will get in acess files, your entered data you can see and modify in acess file.
Read more...