在SQL中插入asp.net问题
问题描述:
字符串或二进制数据将被截断.
该声明已终止.
String or binary data would be truncated.
The statement has been terminated.
string insert = "Insert into RentInformation (UserName,EmailId,Password,ConfirmPassword,Purpose,AdTitle,ADType,DescriptionofAd,RoomType,PropertyType,Mobileno,Address,Image) values ('"+TextBox12.Text+"','"+TextBox2.Text+"','"+TextBox3.Text+"','"+TextBox4.Text+"','"+DropDownList1.SelectedItem+"','"+TextBox18.Text+"','"+DropDownList4.SelectedItem+"','"+TextBox23.Text+"','"+DropDownList5.SelectedItem+"','"+DropDownList6.SelectedItem+"','"+TextBox19.Text+"','"+TextBox20.Text+"','"+Image1.ImageUrl+"') select Purpose from Base where Purpose ='"+DropDownList1.SelectedItem+"' ";
Line 118: cmd = new SqlCommand(insert,con);
Line 119: cmd.ExecuteNonQuery();<big> this line generate Exception</big>
Line 120: con.Close();
Line 121: Response.Write("<script>alert('insert in RentInformation')</script>");
答
当您尝试向表中插入的数据多于指定列的大小时,会发生此错误.
检查要在哪个字段中插入其大小大于databsae中定义的大小的值.
像列"的目的是具有大小Varchar(10),并且您尝试插入的值大于10,然后出现此错误,因为它超出了定义的大小.
Hi,
This error occurs when you try insert data into the table more then the specified size of the column.
Check in which field you are trying to insert value whose size is more then the desfined size in databsae.
Like column Purpose is having size Varchar(10) and you are trying to insert value more then 10 then this error because it exceeds the defined size.