1
votes

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

2
Check the size of your parameters, some of them are bigger than their column size .Arnaud

2 Answers

0
votes

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

1
votes

Whenever you get below error message ... It means field is NOT big enough to hold data.

string or binary data would be truncated