Click here to Skip to main content
15,907,392 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
What is code need to give for save button in c# windows form to saving in SQL database
Posted

sqlconnection conn=new sqlconnection();
sqlcommand cmd=new sqlcommand();
string query="insert into tablename(column1,column2) values('column1 value','column2 value') ";
cmd.connection=conn;
cmd.commandtext=query;
conn.open();
cmd.executenonquery();
conn.close;
 
Share this answer
 
v2
string s = "INSERT into UserDetails values('" + txtemail.Text + "','" + txtfirstname.Text + "','" + txtlastname.Text + "','" + txtpwd.Text + "','" + ddlcountry.SelectedItem.Text + "','" + ddlstate.SelectedItem.Text + " ','" + txtcity.Text + "','" + txtphnumber.Text + "','" + txtaddress1.Text + "','" + txtaddress2.Text + "','" + txtqualification.Text + "','" + txtskills.Text + "')";
            SqlCommand cmd;
            cn = new SqlConnection(conection.getconnection());
            cmd = new SqlCommand(s, cn);
            cn.Open();
            cmd.ExecuteNonQuery();
            cn.Close();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900