Below is my coding
protected void GridView_Updating(object sender, GridViewUpdateEventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=SONY-VAIO\SQLEXPRESS;Initial Catalog=Employee;Integrated Security=True");
con.Open();
Label lb = (Label)GridView.Rows[e.RowIndex].FindControl("Id");
RadioButtonList rd = (RadioButtonList)GridView.Rows[e.RowIndex].FindControl("rdStatus");
CheckBoxList cb = (CheckBoxList)GridView.Rows[e.RowIndex].FindControl("ChkActive");
TextBox tx1 = (TextBox)GridView.Rows[e.RowIndex].FindControl("txtId");
TextBox tx2 = (TextBox)GridView.Rows[e.RowIndex].FindControl("txtName");
TextBox tx3= (TextBox)GridView.Rows[e.RowIndex].FindControl("txtAddress");
DropDownList ddl = (DropDownList)GridView.Rows[e.RowIndex].FindControl("ddlDepartment");
SqlCommand cmd = new SqlCommand("Update Edittable set Name=@Name , Address=@Address,Status=@Status,Active=@Active,Department=@Department,Salary=@Salary WHERE Id=@Id", con);
cmd.Parameters.AddWithValue("@Id", txtId.Text.ToString());
cmd.Parameters.AddWithValue("@Name", txtName.Text.ToString());
cmd.Parameters.AddWithValue("@Address", txtAddress.Text.ToString());
cmd.Parameters.AddWithValue("@Department", ddlDepartment.SelectedValue.ToString());
cmd.Parameters.AddWithValue("@Salary", txtSalary.Text.ToString());
cmd.Parameters.AddWithValue("@Active", ChkActive.SelectedValue.ToString());
cmd.Parameters.AddWithValue("@Status", rdStatus.SelectedValue.ToString());
cmd.ExecuteNonQuery();
GridView.EditIndex = -1;
FillGridView();
}

Biswa Pujarini MohapatraRank #465 · 5.4K reputationPosted Feb 4, 2014, 5:53 PM EST
cmd.parameters.addwithvalue(@id, int32.tryparse(txtid.text);
Biswa Pujarini MohapatraRank #465 · 5.4K reputationPosted Feb 3, 2014, 1:11 AM EST
Rajeev KumarRank #1,937 · 758 reputationPosted Feb 3, 2014, 1:27 AM EST
ALOK SHARMA51 reputationPosted Feb 3, 2014, 1:54 AM EST
Please see my coding above if i have make any mistake as even i have choose datakeynames = "id"
ALOK SHARMA51 reputationPosted Feb 3, 2014, 2:10 AM EST
ALOK SHARMA51 reputationPosted Feb 3, 2014, 2:16 AM EST
ALOK SHARMA51 reputationPosted Feb 3, 2014, 2:38 AM EST
Rajeev KumarRank #1,937 · 758 reputationPosted Feb 3, 2014, 7:38 PM EST
ALOK SHARMA51 reputationPosted Feb 4, 2014, 12:24 AM EST
Rajeev KumarRank #1,937 · 758 reputationPosted Feb 4, 2014, 2:31 AM EST
please use
"Data Source=SONY-VAIO\\SQLEXPRESS;Initial Catalog=Employee;Integrated Security=True"
This line
ALOK SHARMA51 reputationPosted Feb 4, 2014, 5:35 AM EST
i am getting this error Must declare the scalar variable "@Id". Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.SqlClient.SqlException: Must declare the scalar variable "@Id".
Rajeev KumarRank #1,937 · 758 reputationPosted Feb 4, 2014, 6:37 PM EST
see demo. in procedure
@id int,
@ city varchar(10)
uadate table set city=@city where id=@id,
when u will right this query on without procedure,
updaet table set city='Noida' and id='1';
i think u are define datatype int, and inserting value in varchar .
try this if error will not solve please share query.
ALOK SHARMA51 reputationPosted Feb 5, 2014, 9:51 AM EST
Biswa Pujarini MohapatraRank #465 · 5.4K reputationPosted Feb 5, 2014, 10:09 AM EST
ALOK SHARMA51 reputationPosted Feb 5, 2014, 10:39 AM EST
'ddlDepartment' has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value
'ddlDepartment' has a SelectedValue which is invalid because it does not exist in the list of items.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.Parameter name: value
Exception Details: System.ArgumentOutOfRangeException: 'ddlDepartment' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value
But my dropwdownlist is populated. What the error mean. Ty
ALOK SHARMA51 reputationPosted Feb 6, 2014, 5:48 AM EST
Biswa Pujarini MohapatraRank #465 · 5.4K reputationPosted Feb 6, 2014, 6:52 AM EST
http://stackoverflow.com/questions/19770207/dropdownlist-has-a-selectedvalue-which-is-invalid-because-it-does-not-exist-in-t
Ehtesham MehmoodRank #719 · 3.3K reputationPosted Feb 28, 2014, 11:35 PM EST