Search This Blog

Tuesday, April 2, 2013

VB.Net SQL Server Connectivity For Insert New Record

//Create connection object

Dim con1 As New System.Data.SqlClient.SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Documents and Settings\student\Local Settings\Application Data\Temporary Projects\Databaseconvb\Database1.mdf;Integrated Security=True;User Instance=True")

//Create Command Object

Dim cmd As New System.Data.SqlClient.SqlCommand

cmd.CommandType = System.Data.CommandType.Text
     
cmd.CommandText = "INSERT tbl_user VALUES('" + txt_username.Text + "','" + txt_password.Text + "','" + txt_firstname.Text + "','" + txt_lastname.Text + "','" + gender.Text + "','" + txt_mobile.Text + "','" + txt_emailid.Text + "')"

cmd.Connection = con1

        con1.Open()

        cmd.ExecuteNonQuery()

        con1.Close()

// It will perform the query of inserting new record into the table.

No comments:

Post a Comment