Click here to Skip to main content
15,922,145 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
String or binary data would be truncated.
The statement has been terminated.

JavaScript
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>");
Posted
Updated 18-Sep-12 2:01am
v2
Comments
Richard MacCutchan 18-Sep-12 8:04am    
This is a good example of the worst way to code SQL queries. Google for "SQL injection" and rewrite in the recommended form before trying again.
M@anish 18-Sep-12 8:06am    
Hi Sir I m not getting your Point so please Guide me
Richard MacCutchan 18-Sep-12 8:14am    
I just did; go to Google and type in "SQL injection". You will then find some links that explain why your code is written badly, and how to do it properly. When you have learned how to use SQL in the correct way you may even find that your program works.
Sravanthid28 18-Sep-12 8:07am    
once check your query string

1 solution

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.
 
Share this answer
 
Comments
M@anish 18-Sep-12 8:13am    
Thank you, so much

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900