Hi guys..
Please guide me for the database connectivity with sql server express edition 2005 for any website.

A simple code on how to connect sql 2005 from VB.Net or ASP.Net via SQL connection string, and the use of ExecuteNonQuery()

method to execute the command and the try and catch to catch errors during runtime.

Example information:

SQL data:

Database name: user

Table name: user_t

Columns: user_id,lname,fname,username,password,usertype


Controls:

textboxes:

textID = for Id

textlname = for last name

textfname = for first name

textusername = for user name

textpassword = for password

combobox:

comboUsertype = for user type


Code:

Dim con As New SqlClient.SqlConnection

Dim strCon as string = "Data Source=Admin\SQLEXPRESS;Initial Catalog=user;Integrated Security=True"

Dim strCommand as string = “Insert into user_t (user_id, lname, fname, username, password, usertype) values ('”&

me.textID.text &”','” & me.textlname.text &”', '” &me.fname.text &”', '”&me.textusername.text &”','”& me.textpassword.text

&”','”&me.comboUsertype.text &”')”

Sub insert()


con.ConnectionString = strCon

Dim cm As New SqlClient.SqlCommand(strCommand, con)

con.Open()

cm.ExecuteNonQuery()

MsgBox("Succesfully saved…")

con.close

End sub

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.