Saturday, August 6, 2011

How to create Database Connection

first of all write "using system.data.sqlclient" in the header files
Write this code on the button click.

string name, address, course, email;
int mobile;
SqlConnection con=new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString);
con.Open();
SqlCommand cmd = new SqlCommand("Insert into studentinfo Values('" + txtname.Text + "','" + txtaddress.Text + "','" + DropDownList1.Text + "','" + txtemail.Text + "','" + txtmobile.Text + "')", con);
cmd.ExecuteNonQuery();
con.Close();

connection will be established.

No comments:

Post a Comment

social media buttons