I have a GridView
in which I bring information from the database, and with it I also fill DropDownList
but when I want to edit the records this fails and tells me that it could not be converted from DropDownList
a String
or Int
.
This is the code with which I tried to do the update
:
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string myConnectionString = @"C:\Users\gutiece\Desktop\database\" + "Database1.accdb";
using (OleDbConnection connection = new OleDbConnection())
{
using (OleDbCommand command = new OleDbCommand())
{
connection.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0; Data source= " + myConnectionString;
command.Connection = connection;
connection.Open();
GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex];
int id = int.Parse(GridView1.DataKeys[e.RowIndex].Value.ToString());
DropDownList tool = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("gv_tool");
DropDownList area = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("gv_tool");
DropDownList pool = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("gv_tool");
DropDownList team = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("gv_tool");
DropDownList station = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("gv_tool");
DropDownList operation = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("gv_tool");
DropDownList torque = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("gv_tool");
DropDownList tl = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("gv_tool");
command.CommandText = "UPDATE area SET tool_id = '" + tool + "', area = '" + area + "', pool = '" + pool + "', team = " + team + ", station = '" + station + "', operation = '" + operation + "', operation_torque = " + torque + ", tl_name = '" + tl + "' WHERE id = = " + id + "";
command.Parameters.Add("@id", OleDbType.Integer).Value = id;
command.Parameters.Add("@TOOL_ID", OleDbType.VarChar).Value = tool;
command.Parameters.Add("@AREA", OleDbType.VarChar).Value = area;
command.Parameters.Add("@POOL", OleDbType.VarChar).Value = pool;
command.Parameters.Add("@TEAM", OleDbType.Integer).Value = team;
command.Parameters.Add("@STATION", OleDbType.VarChar).Value = station;
command.Parameters.Add("@OPERATION", OleDbType.VarChar).Value = operation;
command.Parameters.Add("@OPERATION_TORQUE", OleDbType.Integer).Value = torque;
command.Parameters.Add("@TL_NAME", OleDbType.VarChar).Value = tl;
command.ExecuteNonQuery();
GridView1.DataBind();
GridView1.EditIndex = -1;
Response.Redirect("asignacion.aspx");
connection.Close();
}
}
}
Failed to convert parameter value from to DropDownList to a String.
I made a BreakPoint
and in each value, nothing comes in only this appears as a value of the variable {System.Web.UI.WebControls.DropDownList}