H
hodgesp
I have a Datagrid that I'm trying to use to update a SQL table. The grid
works and I get the EditCommand to work. When I make a change to a
field, I get a date error. I was getting invalid cast error, but I
changed my Update script. All the scripts I found seem to work up to
that point. What am I missing? BTW-Im using c#.
Here is my Update Script, nor the datetime cast within the parameter
assignment:
private void DataGrid1_UpdateCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
//--retrieve textbox controls from datagrid---//
string iID = e.Item.Cells[1].Text;
string dtDate = e.Item.Cells[3].Text;
string strMeal = e.Item.Cells[4].Text;
string strLodge = e.Item.Cells[5].Text;
//---assign parameters---//
this.sqlCommand1.Parameters.Add("@TripDate",Convert.ToDateTime(dtDate.ToString()));
this.sqlCommand1.Parameters["@Param1"].Value = strMeal.ToString();
this.sqlCommand1.Parameters["@Param2"].Value = strLodge.ToString();
this.sqlCommand1.Parameters["@id"].Value = iID;
//---execute update query script---//
// this.sqlConnection1.Open();
// this.sqlCommand1.ExecuteNonQuery();
//---deselect row for edting---//
this.DataGrid1.EditItemIndex = -1;
this.DataGrid1.ShowFooter = true;
BindGrid();
//---debugging code---//
Response.Write(Convert.ToDateTime(dtDate.ToString()));
}
works and I get the EditCommand to work. When I make a change to a
field, I get a date error. I was getting invalid cast error, but I
changed my Update script. All the scripts I found seem to work up to
that point. What am I missing? BTW-Im using c#.
Here is my Update Script, nor the datetime cast within the parameter
assignment:
private void DataGrid1_UpdateCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
//--retrieve textbox controls from datagrid---//
string iID = e.Item.Cells[1].Text;
string dtDate = e.Item.Cells[3].Text;
string strMeal = e.Item.Cells[4].Text;
string strLodge = e.Item.Cells[5].Text;
//---assign parameters---//
this.sqlCommand1.Parameters.Add("@TripDate",Convert.ToDateTime(dtDate.ToString()));
this.sqlCommand1.Parameters["@Param1"].Value = strMeal.ToString();
this.sqlCommand1.Parameters["@Param2"].Value = strLodge.ToString();
this.sqlCommand1.Parameters["@id"].Value = iID;
//---execute update query script---//
// this.sqlConnection1.Open();
// this.sqlCommand1.ExecuteNonQuery();
//---deselect row for edting---//
this.DataGrid1.EditItemIndex = -1;
this.DataGrid1.ShowFooter = true;
BindGrid();
//---debugging code---//
Response.Write(Convert.ToDateTime(dtDate.ToString()));
}