i am getting " The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.
The statement has been terminated."
public void Insert(String Query)
{
MyCommand.CommandType = CommandType.Text;
MyCommand.CommandText = Query;
MyConnection.Open();
MyCommand.Connection = MyConnection;
MyCommand.ExecuteNonQuery();
MyConnection.Close();
}
Iftikar HussainPosted Jul 23, 2013, 2:45 AM
Try like this
Regards,
Iftikar
Manj NPosted Jul 27, 2013, 12:59 AM
can you tell me, which book is good to learn c# programming and sql .
Sanjeeb LenkaPosted Jul 23, 2013, 3:19 AM
http://social.msdn.microsoft.com/Forums/en-US/f5b6b628-ee32-4d27-a733-9d902ee14e48/error-the-conversion-of-a-varchar-data-type-to-a-datetime-data-type-resulted-in-an-outofrange
try to use parameter to pass the value in insert statement.
Iftikar HussainPosted Jul 23, 2013, 3:13 AM
Regards,
Iftikar
Manj NPosted Jul 23, 2013, 3:09 AM
Iftikar HussainPosted Jul 23, 2013, 3:03 AM
Regards,
Iftikar
Sanjeeb LenkaPosted Jul 23, 2013, 3:02 AM
Manj NPosted Jul 23, 2013, 2:56 AM
Sanjeeb LenkaPosted Jul 23, 2013, 2:48 AM
string StartDate = "07-01-13";// what the value you are passing
string Month = StartDate.Substring(0, 2);//value 07
string Day = StartDate.Substring(3, 2);//value 22
string Year = StartDate.Substring(6, 2); // 13
DateTime NewDate = DateTime.ParseExact(Day + "/" + Month + "/" + Year, "dd/MM/yy", CultureInfo.InvariantCulture);
Manj NPosted Jul 23, 2013, 2:44 AM
Sanjeeb LenkaPosted Jul 23, 2013, 2:39 AM
Manj NPosted Jul 23, 2013, 2:29 AM
/* when i parse this, then i get NewDate as {07-01-2013 00:22:00}.. but i want 07-22-2013*/
Sanjeeb LenkaPosted Jul 23, 2013, 1:51 AM
Manj NPosted Jul 23, 2013, 1:33 AM
Sanjeeb LenkaPosted Jul 23, 2013, 1:07 AM
it will take date as mm/dd/yyyy try to pass like that.
Query = "INSERT INTO TimeSheetBreakDown(DevId,ProjectId,Activity,Description,AdditionalDescription,Hour,Day,Month,Year,WeekStartDate,Date,Estimated)";
Query += "VALUES('" + DeveloperId + "','" + ProjectID + "','" + ActivityId + "',";
Query += "'" + MVtxt.Text + "','" + txtAdditionalDesc.Text + "','" + MVddl.SelectedValue.ToString() + "','" + WeekDay + "','" + Month + "','" + Year + "',";
Query += "Convert(datetime,'" + StartDate + "',103),Convert(datetime,'" + InsertDate + "',103),'" + cbestimate.Checked + "')";
Manj NPosted Jul 23, 2013, 1:04 AM
Sanjeeb LenkaPosted Jul 23, 2013, 12:38 AM
Manj NPosted Jul 23, 2013, 12:32 AM
i tried as you said, then it gives "String was not recognized as a valid DateTime." error.
Sanjeeb LenkaPosted Jul 22, 2013, 8:17 AM
Query = "INSERT INTO TimeSheetBreakDown(DevId,ProjectId,Activity,Description,AdditionalDescription,Hour,Day,Month,Year,WeekStartDate,Date,Estimated)";
Query += "VALUES('" + DeveloperId + "','" + ProjectID + "','" + ActivityId + "',";
Query += "'" + MVtxt.Text + "','" + txtAdditionalDesc.Text + "','" + MVddl.SelectedValue.ToString() + "','" + WeekDay + "','" + Month + "','" + Year + "',";
Query += "'" + Convert.ToDateTime(StartDate) + "','" + Convert.ToDateTime(InsertDate) + "','" + cbestimate.Checked + "')";
Manj NPosted Jul 22, 2013, 7:51 AM
Manj NPosted Jul 22, 2013, 7:50 AM
Manj NPosted Jul 22, 2013, 7:49 AM
Iftikar HussainPosted Jul 22, 2013, 6:57 AM
Please provide your query details
Regards,
Iftikar
Sanjeeb LenkaPosted Jul 22, 2013, 6:56 AM