简体   繁体   中英

error after clicking submit button

code: 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 what it get:

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, Str ing 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

每当您收到以下错误消息时......这意味着字段不足以容纳数据。

string or binary data would be truncated 

whenever you get this type of error ,it means this error is throne by database. you try to insert the record with some of the field whose size is more than given database field size.

Thank you

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM