Open Microsoft SQL Server Management
Create Database in SQL Server with name : DBTM
Create table : TBL_PRODUCT
Below design TBL_PRODUCT
After that, please open Visual Basic 6.0 in your computer
Create Design Form1 like below picture
place below code in form1 :
Dim Conn As New ADODB.Connection
Dim RSProduct As ADODB.Recordset
Sub OpenDB()
Set Conn = New ADODB.Connection
Set RSProduct = New ADODB.Recordset
Conn.Open "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=DBTM;Data Source=YOURCOMPUTERNAME"
End Sub
Private Sub Form_Load()
Call OpenDB
Adodc1.ConnectionString = Conn
Adodc1.RecordSource = "TBL_PRODUCT"
Adodc1.Refresh
Set DataGrid1.DataSource = Adodc1
End Sub
Run your project
Below for the result :
0 Response to "VB 6.0 - How to connect SQL Server Database"