Note that there are some explanatory texts on larger screens.

plurals
  1. POError: the conversion of a varchar data type to a datetime data type resulted in an out-of-range value
    primarykey
    data
    text
    <p>I'm trying to enter data into my SQL Server 2008 using data from a form. I am using a DateTimePicker to select dates from a form and enters this data to the db, however when I try to run the form I'm getting the following error:</p> <blockquote> <p><em>The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.<br> The statement has been terminated</em></p> </blockquote> <p>This is the code for my form below:</p> <pre><code>private void btnAddBooking_Click(object sender, EventArgs e) { DateTime requested = dtpRequested.Value; DateTime pickup = dtpPickup.Value; DateTime estDropoff = dtpEstimatedDrop.Value; SAF.AddNewBooking(requested, pickup, estDropoff, selectedStatus.StatusId, selectedRate.RateId); dtpRequested.CustomFormat = " "; dtpPickup.CustomFormat = " "; dtpEstimatedDrop.CustomFormat = " "; cbStatus.SelectedIndex = 0; cbRateOfPayment.SelectedIndex = 0; MessageBox.Show("Booking Created"); tabControl2.SelectTab(2); } </code></pre> <p>Here is code in the facade where I store the method:</p> <pre><code>public void AddNewBooking(DateTime requestedD, DateTime pickupD, DateTime estDropOff, int statusId, int rateId) { dao.AddNewBooking(requestedD, pickupD, estDropOff, statusId, rateId); }//end CreateBooking </code></pre> <p>and this is the <code>INSERT</code> statement code in my DAO:</p> <pre><code>sql = "INSERT INTO [Transaction] (TransactionId, RequestedDateOfPickup, ActualDateOfPickup, EstimatedDropOffDate, StatusId, RateId)"; sql += String.Format("VALUES('{0}', '{1}', '{2}', '{3}', {4}, {5})", transactionId, requestedD, pickupD, estDropOff, statusId, rateId); cn = new SqlConnection(Properties.Settings.Default.UKRENTALSConnectionString); cmd = new SqlCommand(sql, cn); cn.Open(); cmd.ExecuteNonQuery(); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload