我在TXT_Firm_Pincode.Text
和TXT_Firm_Bank_Ac_No.Text
中提供数字数据时,在插入和更新时遇到错误,当我离开这两个字段时,它们的完美表现可以帮助任何人。
MC.Cmd_SQL = new OleDbCommand($@"Update TBL_Firm set
Firm_Owner = '{TXT_Firm_Owner.Text}',
Firm_Name = '{TXT_Firm_Name.Text}',
Firm_Address = '{TXT_Firm_Address.Text}',
Firm_City = '{TXT_Firm_City.Text}',
Firm_Pincode = @Firm_Pincode,
Firm_State= '{CB_Firm_State.Text}',
Firm_Con_Person = '{TXT_Firm_Con_Person.Text}',
Firm_Con_No = {TXT_Firm_Con_No.Text},
Firm_GSTN = '{TXT_Firm_GSTN.Text}',
Firm_Bank_Name = '{TXT_Firm_Bank_Name.Text}',
Firm_Bank_Ac_No = @Firm_Bank_Ac_No,
Firm_Bank_Branch = '{TXT_Firm_Bank_Branch.Text}',
Firm_Bank_IFSC= '{TXT_Firm_Bank_IFSC.Text}',
Firm_MailID = '{TXT_Firm_MailID.Text}'
where Firm_ID = {TXT_Firm_ID.Text}", MC.DB_Connection);
MC.Cmd_SQL.CommandType = CommandType.Text;
MC.Cmd_SQL.Parameters.AddWithValue("@Firm_Pincode" , TXT_Firm_Pincode.Text == "" ? DBNull.Value : (object)"Null");
MC.Cmd_SQL.Parameters.AddWithValue("@Firm_Bank_Ac_No", TXT_Firm_Bank_Ac_No.Text == "" ? DBNull.Value : (object)"Null");
MC.Cmd_SQL.ExecuteNonQuery();
答案 0 :(得分:0)
当condition ? operand1 : operand2
为真和假时,三元运算符operand1
返回condition
-否则。
您的operand1
语句可以,但是您需要更改operand2
以便在其中添加文本框值:
MC.Cmd_SQL.Parameters.AddWithValue("@Firm_Pincode" ,
TXT_Firm_Pincode.Text == "" ? DBNull.Value : TXT_Firm_Pincode.Text);
MC.Cmd_SQL.Parameters.AddWithValue("@Firm_Bank_Ac_No",
TXT_Firm_Bank_Ac_No.Text == "" ? DBNull.Value : TXT_Firm_Bank_Ac_No.Text);