hii all i am new in asp.net.i am trying to implement a grid view with all functionalities(insert,update delete).
i have successfullly done edit,update and cancel.but not able to insert(new record) in grid view.As soon as i click on insert i get exception as:
Exception Details: System.Data.SqlClient.SqlException: Must declare the scalar variable "@EmployeeNo".Means i need to declare this in my c# page but how???my code for inserting is:
in my database i have columns as :
EmployeeNO(int),Name(nvarchar),Nick(nvarchar)
thankzzz
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName.Equals("Insert"))
{
TextBox txtNewEmployeeNo = (TextBox)GridView1.FooterRow.FindControl("txtNewEmployeeNo");
TextBox txtNewName = (TextBox)GridView1.FooterRow.FindControl("txtNewName");
TextBox txtNewNick = (TextBox)GridView1.FooterRow.FindControl("txtNewNick");
// and ur insert code goes here.....
String ConnectionString = "server=alok-pc;database=db_test;user id=sa;password=alokamar123456;";
SqlConnection Conn = new SqlConnection(ConnectionString);
Conn.Open();
SqlDataAdapter da = new SqlDataAdapter("insert into tab1(EmployeeNo,Name,Nick) values (@EmployeeNo,@Name,@Nick)", Conn);
DataSet ds = new DataSet();
da.Fill(ds, "emp");
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
Conn.Close();
}
}