代码: protected void Button1_Click(object sender,EventArgs e) { 尝试 { Guid newGUID = Guid.NewGuid();
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString);
conn.Open();
string insertQuery = "insert into UserData1 (ID,First_Name,Middle_Name,Last_Name,Your_Location,Tour_Loacation,Members,Departure,Returndt,Phone_no,Mobile_no,Email,Card_no,Cvv,Amt)values(@id,@fname,@mname,@lname,@yloc,@tloc,@mem,@dept,@ret,@pho,@mob,@email,@cardno,@cvv,@amt)";
SqlCommand com = new SqlCommand(insertQuery, conn);
com.Parameters.AddWithValue("@id", newGUID.ToString());
com.Parameters.AddWithValue("@fname", TextBoxUfn.Text);
com.Parameters.AddWithValue("@mname", TextBoxUmn.Text);
com.Parameters.AddWithValue("@lname", TextBoxUln.Text);
com.Parameters.AddWithValue("@yloc", TextBoxUyloc.Text);
com.Parameters.AddWithValue("@tloc", TextBoxUtloc.Text);
com.Parameters.AddWithValue("@mem", DropDownListUmem.SelectedItem.ToString());
com.Parameters.AddWithValue("@dept", TextBoxUdep.Text);
com.Parameters.AddWithValue("@ret", TextBoxUret.Text);
com.Parameters.AddWithValue("@pho", TextBoxUphoneno.Text);
com.Parameters.AddWithValue("@mob", TextBoxUmobileno.Text);
com.Parameters.AddWithValue("@email", TextBoxUemail.Text);
com.Parameters.AddWithValue("@cardno", TextBox1UCardno.Text);
com.Parameters.AddWithValue("@cvv", TextBox2Ucvv.Text);
com.Parameters.AddWithValue("@amt", TextBox3Uamt.Text);
conn.Close();
com.Connection.Open();
com.ExecuteNonQuery();
Response.Redirect("managerbook.aspx");
Response.Write("Booking is successfull");
}
catch (Exception ex)
{
Response.Write("Error:" + ex.ToString());
}
}
}
错误结果:
错误:System.Data.SqlClient.SqlException:字符串或二进制数据将被截断。该语句已终止。 System.Data.SqlClient.SqlConnection.OnError(SqlException异常,布尔breakConnection)处于系统的System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)的System.Data.SqlClient.SqlInternalConnection.OnError(SqlException异常,布尔breakConnection) System.Data.SqlClient上的System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds,RunBehavior runBehavior,String resetOptionsString)中的.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior,SqlCommand cmdHandler,SqlDataReader dataStream,BulkCopySimpleResultSet bulkCopyHandler,TdsParserStateObject stateObj) System.Data.SqlClient上的System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior,RunBehavior runBehavior,Boolean returnStream,String方法,DbAsyncResult结果)中的.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior,RunBehavior runBehavior,Boolean returnStream,Boolean async)。 SqlCommand.InternalExecuteNonQuery(DbAsyncResult结果,Str在system.Data.SqlClient.SqlCommand.ExecuteNonQuery()中的System.Data.SqlClient.SqlCommand.ExecuteNonQuery()处于c:\ Users \ HP \ Documents \ Visual Studio 2008 \ Projects \ loginPage \ loginPage \ User中的User.Button1_Click(Object sender,EventArgs e)中的ing methodName,Boolean sendToPipe) .aspx.cs:第58行
答案 0 :(得分:1)
每当你收到以下错误信息时......这意味着字段不足以保存数据。
string or binary data would be truncated
答案 1 :(得分:0)
每当遇到此类错误时,都表示此错误是数据库的错误。 您尝试使用一些大小超过的字段插入记录 给定数据库字段大小。
谢谢