Answer the question
In order to leave comments, you need to log in
System.Data.SqlClient.SqlException: "String or binary data would be truncated. The statement has been terminated."?
protected void btnUpdate_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings
["StudentConnectionString"].ConnectionString);
conn.open();
SqlCommandcmd;
SqlDataAdapter adapter = new SqlDataAdapter();
String sql = "";
sql = "update Students set firstName = '" + txtBoxfName + "'," +
" lastName = '" + txtBoxlName + "', " +
"studentNo = '" + Convert.ToInt32(txtBoxStudentNo.Text) +
"' where id_student ='"
cmd = new SqlCommand(sql, conn);
adapter.InsertCommand = new SqlCommand(sql, conn);
adapter.InsertCommand.ExecuteNonQuery(); // problem appears on this line
Label2.Text = "student successfully updated";
txtBoxfName.Text = " ";
txtBoxlName.Text = " ";
txtBoxStudentNo.Text = " ";
cmd.dispose();
conn.Close();
}
Answer the question
In order to leave comments, you need to log in
This error means that you are trying to write a string longer than the field allows, probably firstName or lastName. This check can be disabled, for example, via SET ANSI_WARNINGS ON|OFF, or you can cut the string to fit the field size.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question