Click here to Skip to main content
15,896,348 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
See more:
i have 3 text boxes i need to save the entered text in my sql table
Posted
Comments
Richard C Bishop 23-Oct-13 11:05am    
Ok.......go!
joshrduncan2012 23-Oct-13 11:12am    
Sounds good to me. Please proceed.

1 solution

private void btnSaveData_Click(object sender, EventArgs e)
{
string sql="insert into customer(customername,contactno,email)values('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "')";
try
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "data source=rakesh-PC; Initial catalog=mysoftdb; user id=sa;password=ruhil";
con.Open();
SqlCommand objCmd = new SqlCommand(sql, con);
SqlDataAdapter objDA = new SqlDataAdapter(objCmd);
DataSet ds = new DataSet();
objDA.Fill(ds, "dtEmployee");
MessageBox.Show("Data has been saved");
}
catch (Exception ex)
{
MessageBox.Show("error is " + ex.Message);
}
}
This code is used to save date in ms sql server u can replace little syntax for other databases.
 
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