Reputation: 29
Hi guys Iwant to assign a combobox value to stored procedure to insert data into a table
cmd.Parameters.Add("@post_name", SqlDbType.VarChar).Value = comboBox1.SelectedItem.ToString().Trim();
When am assign to MessageBox
MessageBox.Show(comboBox1.SelectedValue.ToString());
System.Data.DataRowView
But it shows error like
String or binary data would be truncated. The statement has been terminated.
Can y explain wt is the problem.
Upvotes: 0
Views: 1105
Reputation: 140803
What happen if you do this:
string title = comboBox1.SelectedItem.ToString().Trim();
SqlParameter parameter = new SqlParameter("post_name", SqlDbType.VarChar);
parameter.Size = title.Length;
parameter.Value = title ;
cmd.Parameters.Add(parameter);
The error is telling you that you have reach the upper limit of the Varchar. By default, the varchar will take the size of the string.
Upvotes: 0
Reputation: 2384
Error Message:
String or binary data would be truncated.
Severity level: 16.
Description: This error message appears when you try to insert a string with more characters than the column can maximal accommodate.
copied from here: String or binary data would be truncated
Upvotes: 2