在gridview中更新行时输入字符串的格式不正确?

时间:2018-11-14 17:15:33

标签: asp.net sql-server

将我的OrderStatus'P'更新为'A'时出现问题。数据类型输入  SQL Server是varchar(50)

 protected void grdNewOrder_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
using (SqlConnection sqlCon = new SqlConnection(constring))
        {
            sqlCon.Open();
            string query = "UPDATE tblPurchase SET OrderStatus ='A' WHERE PurchaseID= @id";
            SqlCommand sqlCmd = new SqlCommand(query, sqlCon);
            sqlCmd.Parameters.AddWithValue("@id", Convert.ToInt32(grdNewOrder.DataKeys[e.RowIndex].Value.ToString()));
            sqlCmd.ExecuteNonQuery();

            LoadNewOrders();

            lblsucessmsg.Text = "Selected Record Updated";
            lblerror.Text = "";
        }
    }
    catch (Exception ex)
    {
        lblsucessmsg.Text = "";
        lblerror.Text = ex.Message;
    }

0 个答案:

没有答案