我想同时更新Cliente和NrDoc,但是我在使用此代码时遇到了麻烦,因为它不允许我同时更新这两个代码
protected void Sqldata_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
try
{
using (SqlConnection sqlcon = new SqlConnection(connection))
{
sqlcon.Open();
string query = "UPDATE NaoMatch SET Cliente = @Cliente AND SET NrDoc=@NrDoc where ID = @Id "; //Update dos dados...
SqlCommand sqlcmd = new SqlCommand(query,sqlcon); //Para executar as queries o sqlcommand tem de ser criado, para isso tem que haver um sqlconnection
Debug.Write(query);
sqlcmd.Parameters.AddWithValue("@Cliente", (Sqldata.Rows[e.RowIndex].FindControl("txtCliente") as TextBox).Text.Trim());
sqlcmd.Parameters.AddWithValue("@NrDoc", (Sqldata.Rows[e.RowIndex].FindControl("txtDoc") as TextBox).Text.Trim());
sqlcmd.Parameters.AddWithValue("@Id", Convert.ToInt32(Sqldata.DataKeys[e.RowIndex].Value.ToString()));
sqlcmd.ExecuteNonQuery();
Sqldata.EditIndex = -1;
populateGridView();
}
}
catch (Exception ex)
{
Response.Write(ex);
}
}