无法将值NULL插入列'CNIC'列中不允许为空. INSERT失败.该语句已终止.我已经从数据库表中删除了CNIC列.仍然... [英] Cannot insert the value NULL into column 'CNIC' column does not allow nulls. INSERT fails. The statement has been terminated. i had already deleted the CNIC column from database table. still...

查看:139
本文介绍了无法将值NULL插入列'CNIC'列中不允许为空. INSERT失败.该语句已终止.我已经从数据库表中删除了CNIC列.仍然...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

   String query = "insert into Accounts(Account_No,Account_title,Entry_Date,Initial_Deposite,Account_type,Account_Nature,Postal_Code,District,City,Name,Father_name,Husband_name,Occupation,Mobile,Gender,Marital_status)values(@Account_No,@Account_title,@Entry_Date,@Initial_Deposite,@Account_type,@Account_Nature,@Postal_Code,@District,@city,@Name,@Father_name,@Husband_name,@Occupation,@Mobile,@Gender,@Marital_status)";
                        SqlCommand cmd = new SqlCommand(query, cn);
                        cmd.Prepare();
                        cmd.Parameters.AddWithValue("@Account_No", txtac1.Text + "-" + txtac2.Text);
 cmd.Parameters.AddWithValue("@Account_title", txtaccounttitle.Text);
cmd.Parameters.AddWithValue("@Entry_Date", dateTimePicker1.Value.Date);
cmd.Parameters.AddWithValue("@Initial_Deposite", txtinitial.Text + "/-");
cmd.Parameters.AddWithValue("@Account_type", txttype.Text);
cmd.Parameters.AddWithValue("@Account_Nature", cboaccountnature.SelectedItem);
cmd.Parameters.AddWithValue("@Postal_code", txtpostal.Text);
cmd.Parameters.AddWithValue("@District", cbodistrict.SelectedItem);
cmd.Parameters.AddWithValue("@City", cbocity.SelectedItem);
cmd.Parameters.AddWithValue("@Name", txtname1.Text);
cmd.Parameters.AddWithValue("@Father_name", txtfather1.Text);
cmd.Parameters.AddWithValue("@Husband_name", txthusband1.Text);
cmd.Parameters.AddWithValue("@Occupation", txtoccupation1.Text);
cmd.Parameters.AddWithValue("@Mobile", cbocode.Text + "-" + txtmobile1.Text);
cmd.Parameters.AddWithValue("@Marital_status", cbomarital.Text);
if (rdomale.Checked == true)
 cmd.Parameters.AddWithValue("@Gender", rdomale.Text);
 else if (rdofemale.Checked == true)
cmd.Parameters.AddWithValue("@Gender", rdofemale.Text);
cmd.ExecuteNonQuery();
                        MessageBox.Show("Record Stored Successfully", "Success Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                          }

推荐答案

将以下函数粘贴到代码中.并在使用字符串或文本的任何地方调用此函数.例如textbox1.text.NullToString().

Paste the following function inside the code. and call this function wherever you are using string or text. for eg textbox1.text.NullToString().

public static string NullToString(this object obj)
        {
            return (obj.IsNull() ? string.Empty : Convert.ToString(obj));
        }


我认为您的单选按钮仍然存在问题.我认为两个单选按钮均未选中,并且列不允许为空.
I think problem persist with your radio button. i think both radio button not checked and column not allow null.


这篇关于无法将值NULL插入列'CNIC'列中不允许为空. INSERT失败.该语句已终止.我已经从数据库表中删除了CNIC列.仍然...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆