代碼:錯誤按鈕
protected void Button1_Click(object sender, EventArgs e)
{
try
{
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());
}
}
}
錯誤它所獲得:
Error:System.Data.SqlClient.SqlException: String or binary data would be truncated. The statement has been terminated. at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() at User.Button1_Click(Object sender, EventArgs e) in c:\Users\HP\Documents\Visual Studio 2008\Projects\loginPage\loginPage\User.aspx.cs:line 58
檢查參數的大小,其中一些參數的大小大於它們的列大小。 – Berger