I have three textboxes a GridView with three columns Roll,name & marks, I want that when the user enter data in three textboxes & click on button,then the data added to GridvIew Columns. Foll code Add the Data to database.
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
SqlConnection conn =new SqlConnection (ConfigurationManager.ConnectionStrings["Connection"].ConnectionString ) ;
string query;
SqlCommand cmd;
protected void Button1_Click(object sender, EventArgs e)
{
try
{
query = "Insert into Testing_ViewState values(@Roll,@Name,@Marks)";
cmd = new SqlCommand(query, conn);
cmd.Parameters.AddWithValue("@Roll", txtRoll.Text);
cmd.Parameters.AddWithValue("@Name", txtName.Text);
cmd.Parameters.AddWithValue("@Marks", txtmarks.Text);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
}
catch (Exception ex)
{
lblError.Text = ex.Message.ToString();
}
}
}