2016-03-21 68 views
1

代碼:錯誤按鈕

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

+1

檢查參數的大小,其中一些參數的大小大於它們的列大小。 – Berger

回答

1

每當你得到以下錯誤信息......這意味着字段不是大到足以容納數據。

string or binary data would be truncated 
0

無論何時出現這種類型的錯誤,這意味着這個錯誤是數據庫的王位。 您試圖插入具有給定數據庫字段大小的大於 的某些字段的記錄。

謝謝