Tuesday, 18 September 2012

ASP .NET


1.To save data from text box to database:




Naming: 
1. Textbox for name: txtname
2.Textbox for city: txtcity
3. Button for submit: btnsubmit
4.Button for clear: btnclear


In the namespace you must use the following namespace for database connectivity.

using System.Data.SqlClient;

Code for submit button:      


string str = "Data Source=DESAI-PC\\SQLEXPRESS;Initial Catalog=new1;Integrated Security=True";
 SqlConnection con = new SqlConnection(str);
 con.Open();
string sql = "insert into text2db values('" + txtname.Text + "','" + txtcity.Text + "')";
SqlCommand cmd = new SqlCommand(sql, con);
cmd.ExecuteNonQuery();
con.Close();


Code for clear button: 

txtname.Text = "";
txtcity.Text = "";

No comments:

Post a Comment

POST YOUR COMMENTS AND FAQ........