Can anyone help me by giving out a complete tutorial on the step by step way a connecting to a database using VB?

mani-hellboy commented: Its VB.net forum not VB6 +0

Recommended Answers

All 2 Replies

hello Awais
try this code

Dim cn As ADODB.Connection 'ADODB Connection Object
        Dim rs As New ADODB.Recordset 'Recordset Object
        Dim sqlStr As String ' String variable to store sql command
        
        Set cn = New ADODB.Connection
        
        cn.ConnectionString = "Provider = MSDASQL;" & _
            "Data Source=LocalServer;" & _
            "Initial Catalog=sample;" & _
            "Login ID=SERVANT;" & _
            "Driver=SQL Server;"

        cn.Open
 'your code        
        cn.Close

Note that is for connect ur frontend with sql database server

hi awaise ali,

to connect vb.net with data base first we need the sql connection.

so we write a connection string. to write a connection string first creat a connection variable like this

dim con as new sqlconnection

next we need the connection string that indicate the sql server

that is like
dim costring as string

constring="server=servername;userid=your suer id;password=your password;database="your database name"

after this you need to connect with the server

con=new sqlconnection(constring)

now u r connected with the data base server

after this
con.open() 'for open the connection

do your command here

con.close()

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.