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 MohapatraPosted Feb 4, 2014, 10:53 PM
cmd.parameters.addwithvalue(@id, int32.tryparse(txtid.text);
Ehtesham MehmoodPosted Mar 1, 2014, 4:35 AM
Biswa Pujarini MohapatraPosted Feb 6, 2014, 11:52 AM
http://stackoverflow.com/questions/19770207/dropdownlist-has-a-selectedvalue-which-is-invalid-because-it-does-not-exist-in-t
ALOK SHARMAPosted Feb 6, 2014, 10:48 AM
ALOK SHARMAPosted Feb 5, 2014, 3:39 PM
'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
Biswa Pujarini MohapatraPosted Feb 5, 2014, 3:09 PM
ALOK SHARMAPosted Feb 5, 2014, 2:51 PM
Rajeev KumarPosted Feb 4, 2014, 11:37 PM
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 SHARMAPosted Feb 4, 2014, 10:35 AM
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 KumarPosted Feb 4, 2014, 7:31 AM
please use
"Data Source=SONY-VAIO\\SQLEXPRESS;Initial Catalog=Employee;Integrated Security=True"
This line
ALOK SHARMAPosted Feb 4, 2014, 5:24 AM
Rajeev KumarPosted Feb 4, 2014, 12:38 AM
ALOK SHARMAPosted Feb 3, 2014, 7:38 AM
ALOK SHARMAPosted Feb 3, 2014, 7:16 AM
ALOK SHARMAPosted Feb 3, 2014, 7:10 AM
ALOK SHARMAPosted Feb 3, 2014, 6:54 AM
Please see my coding above if i have make any mistake as even i have choose datakeynames = "id"
Rajeev KumarPosted Feb 3, 2014, 6:27 AM
Biswa Pujarini MohapatraPosted Feb 3, 2014, 6:11 AM