我正在处理我的项目,并且在执行dbm.SubmitChanges()时出现“字符串或二进制数据将被截断”错误;
privatevoid btn_ok_Click(object sender, EventArgs e)
{
myDataClasses_LinqDataContext dbm = newmyDataClasses_LinqDataContext();
myDataClasses_LinqDataContext dbp = newmyDataClasses_LinqDataContext();
if (rdo_main.Checked == true)
{
string sh_shenase = txtshenase.Text;
string name = txtname.Text;
string family = txtfamily.Text;
string sh_shenasname = txtshenasname.Text;
string sh_meli = txtshmeli.Text;
string tt_ruz = cmbroz.Text;
string tt_mah = cmbmah.Text;
string tt_sal = cmbsal.Text;
string loc_tavalod = cmbshahr.Text;
string name_pedar = txtfathername.Text;
string vaz_tahol = cmbvaztahol.Text;
string sh_pishtel = txtshPtamas.Text;
string sh_tel = txtshtamas.Text;
string mobile = txtshmobile.Text;
string email = txtemail.Text;
string address = txtaddres.Text;
string mov_nazari = txtmovazafi_nazari.Text;
string mov_amali = txtmovazafi_amali.Text;
MemoryStream ms = newMemoryStream();
pictureBox1.Image.Save(ms, pictureBox1.Image.RawFormat);
byte[] arrpic = ms.GetBuffer();
tbl_pro_main tbl = newtbl_pro_main()
{
address = address,
birth_date = tt_ruz,
birth_loc = loc_tavalod,
birth_month = tt_mah,
birth_year = tt_sal,
bound_a = mov_amali,
bound_n = mov_nazari,
email = email,
family = family,
id = sh_shenasname,
m_status = vaz_tahol,
mobile_num = mobile,
n_cod = sh_meli,
name = name,
name_father = name_pedar,
phone_num = sh_tel,
phone_pnum = sh_pishtel,
pic = arrpic,
username = sh_shenase
};
dbm.tbl_pro_mains.InsertOnSubmit(tbl);
**dbm.SubmitChanges();**// error `String or binary data would be truncated`!!!!!
MessageBox.Show("success!", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
elseif (rdo_public.Checked ==true)
{
string sh_shenase = txtshenase.Text;
string name = txtname.Text;
string family = txtfamily.Text;
string sh_shenasname = txtshenasname.Text;
string sh_meli = txtshmeli.Text;
string tt_ruz = cmbroz.Text;
string tt_mah = cmbmah.Text;
string tt_sal = cmbsal.Text;
string loc_tavalod = cmbshahr.Text;
string name_pedar = txtfathername.Text;
string vaz_tahol = cmbvaztahol.Text;
string sh_pishtel = txtshPtamas.Text;
string sh_tel = txtshtamas.Text;
string mobile = txtshmobile.Text;
string email = txtemail.Text;
string address = txtaddres.Text;
string mov_nazari = txtmovazafi_nazari.Text;
string mov_amali = txtmovazafi_amali.Text;
MemoryStream ms = newMemoryStream();
pictureBox1.Image.Save(ms, pictureBox1.Image.RawFormat);
byte[] arrpic = ms.GetBuffer();
tbl_pro_public tbl = newtbl_pro_public()
{
address = address,
birth_date = tt_ruz,
birth_loc = loc_tavalod,
birth_month = tt_mah,
birth_year = tt_sal,
bound_a = mov_amali,
bound_n = mov_nazari,
email = email,
family = family,
id = sh_shenasname,
m_status = vaz_tahol,
mobile_num = mobile,
n_cod = sh_meli,
name = name,
name_father = name_pedar,
phone_num = sh_tel,
phone_pnum = sh_pishtel,
pic = arrpic,
username = sh_shenase
};
dbp.tbl_pro_publics.InsertOnSubmit(tbl);
dbp.SubmitChanges();
MessageBox.Show("success!", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
MessageBox.Show("success!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
答案 0 :(得分:4)
这意味着您的某个字段被过长的值溢出。根据列定义检查输入
答案 1 :(得分:0)
是的,当您提到数据库字段的限制时会发生这种情况,例如
Name field is nvarchar(50)
而且你添加的东西超过了这个限制,那么显然会出现错误。
所以有解决方案,
1)扩展DB中字段的大小。
2)限制UI中字段的大小。 (就像添加验证器一样,输入限制值)。