Tengo un GridView
en el cual traigo información desde la base de datos, y con ella también lleno los DropDownList
pero al momento de querer editar los registros este falla y me dice que no se ha podido convertir de DropDownList
a String
o Int
.
Este es el código con el que intenté hacer el 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 a DropDownList to a String.
Hice un BreakPoint
y en cada valor, no entra nada solo aparece esto como valor de la variable {System.Web.UI.WebControls.DropDownList}