C# 编辑

 if (state == "编辑")
                {

                    ht["修改人"] = Helper.用户名;
                    ht["修改时间"] = DateTimeHelper.ServerTime;
                    //ht["产品id"] = ;
                    var dt = dal半成品.check_idexit(txt产品名称.Text.Trim()); //返回的产品id 和产品名称
                    if (dt.Rows.Count == 0 || dt.Rows[0]["产品id"].ToString() == dgr.Cells["产品id"].Value.ToString()) //未找到该名称 ;
                    {
                        SQLHelper.UpdateByHashtable("B_Product", "产品id", dgr.Cells["产品id"].Value.ToString(), ht);
                        MsgBox.Info("修改成功!");
                        RefreshEvent();
                        this.Close();

                    }
                    else
                    {
                        MsgBox.Info("产品名称已存在!");
                        return;
                    }

                }
原文地址:https://www.cnblogs.com/enych/p/11819079.html