Any help will be greatly appreciated!
I have a problem in my edit control on a datagrid. All of the fields are varchar except amount which is float. The problem is when I try to build my SQL update string. With this line in I get an error. With this line out no error:
"amount = '" + famount.Replace("'","''")+ "'," +
What am I doing wrong in the following code?
Thanks iRead
public void People_Update(Object sender, DataGridCommandEventArgs e)
{
string FirstName = ((TextBox)e.Item.Cells[1].Controls[1]).Text;
string MiddleName = ((TextBox)e.Item.Cells[2].Controls[1]).Text;
string LastName = ((TextBox)e.Item.Cells[3].Controls[1]).Text;
string socialSecurityNumber = ((TextBox)e.Item.Cells[4].Controls[1]).Text;
string amount = ((TextBox)e.Item.Cells[5].Controls[1]).Text;
float famount = (float)Convert.ToDouble(amount);
SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["DataSource"]);
connUpdate.Open();
String sql_edit = "UPDATE ContactMatch" +
" SET FirstName = '" + FirstName.Replace("'","''")+ "'," +
"MiddleName = '" + MiddleName.Replace("'","''")+ "'," +
"LastName = '" + LastName.Replace("'","''")+ "'," +
"amount = '" + famount.Replace("'","''")+ "'," +
"socialSecurityNumber = '" + socialSecurityNumber.Replace("'","''")+ "'" +
" WHERE contactID = " + e.Item.Cells[0].Text;
SqlCommand sqlCommandUpdate = new SqlCommand(sql_edit,connUpdate);
sqlCommandUpdate.ExecuteNonQuery();
connUpdate.Close();
sql = "Select * FROM ContactMatch";
People.EditItemIndex = -1;
People.DataSource = CreateDataSource();
People.DataBind();
}
I have a problem in my edit control on a datagrid. All of the fields are varchar except amount which is float. The problem is when I try to build my SQL update string. With this line in I get an error. With this line out no error:
"amount = '" + famount.Replace("'","''")+ "'," +
What am I doing wrong in the following code?
Thanks iRead
public void People_Update(Object sender, DataGridCommandEventArgs e)
{
string FirstName = ((TextBox)e.Item.Cells[1].Controls[1]).Text;
string MiddleName = ((TextBox)e.Item.Cells[2].Controls[1]).Text;
string LastName = ((TextBox)e.Item.Cells[3].Controls[1]).Text;
string socialSecurityNumber = ((TextBox)e.Item.Cells[4].Controls[1]).Text;
string amount = ((TextBox)e.Item.Cells[5].Controls[1]).Text;
float famount = (float)Convert.ToDouble(amount);
SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["DataSource"]);
connUpdate.Open();
String sql_edit = "UPDATE ContactMatch" +
" SET FirstName = '" + FirstName.Replace("'","''")+ "'," +
"MiddleName = '" + MiddleName.Replace("'","''")+ "'," +
"LastName = '" + LastName.Replace("'","''")+ "'," +
"amount = '" + famount.Replace("'","''")+ "'," +
"socialSecurityNumber = '" + socialSecurityNumber.Replace("'","''")+ "'" +
" WHERE contactID = " + e.Item.Cells[0].Text;
SqlCommand sqlCommandUpdate = new SqlCommand(sql_edit,connUpdate);
sqlCommandUpdate.ExecuteNonQuery();
connUpdate.Close();
sql = "Select * FROM ContactMatch";
People.EditItemIndex = -1;
People.DataSource = CreateDataSource();
People.DataBind();
}