當我執行出現此錯誤信息的代碼:如何解決System.Data.SqlClient.SqlException:字符串或二進制數據將被截斷
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(str);
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "Companyregister";
cmd.Parameters.AddWithValue("@Company_name", txtname.Text);
cmd.Parameters.AddWithValue("@Register_no", txtreg_no.Text);
cmd.Parameters.AddWithValue("@Type", DropDownList1.Text);
cmd.Parameters.AddWithValue("@Address", txtadrs.Text);
cmd.Parameters.AddWithValue("@Email", txtemail.Text);
cmd.Parameters.AddWithValue("@Contact_no", txtphone.Text);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
Response.Write("Register succesful");
}
錯誤:
An exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll but was not handled in user code
Additional information: String or binary data would be truncated.
The statement has been terminated.
是什麼在我的代碼或我的存儲過程中導致此異常錯誤,我該如何解決?
SP'Companyregister'是如何定義的? –
您的一個參數的長度必須超過存儲過程中指定的長度。 – Sagar
檢查您的列的最大長度,您可能試圖將一個字符串保存爲11個字符到一個需要10個字符的列 – Dumisani