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 HussainRank #423 · 5.9K reputationPosted Jul 22, 2013, 10:45 PM EDT
Try like this
Regards,
Iftikar
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jul 22, 2013, 2:56 AM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 22, 2013, 2:57 AM EDT
Please provide your query details
Regards,
Iftikar
Manj N144 reputationPosted Jul 22, 2013, 3:49 AM EDT
Manj N144 reputationPosted Jul 22, 2013, 3:50 AM EDT
Manj N144 reputationPosted Jul 22, 2013, 3:51 AM EDT
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jul 22, 2013, 4:17 AM EDT
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 N144 reputationPosted Jul 22, 2013, 8:32 PM EDT
i tried as you said, then it gives "String was not recognized as a valid DateTime." error.
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jul 22, 2013, 8:38 PM EDT
Manj N144 reputationPosted Jul 22, 2013, 9:04 PM EDT
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jul 22, 2013, 9:07 PM EDT
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 N144 reputationPosted Jul 22, 2013, 9:33 PM EDT
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jul 22, 2013, 9:51 PM EDT
Manj N144 reputationPosted Jul 22, 2013, 10:29 PM EDT
/* when i parse this, then i get NewDate as {07-01-2013 00:22:00}.. but i want 07-22-2013*/
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jul 22, 2013, 10:39 PM EDT
Manj N144 reputationPosted Jul 22, 2013, 10:44 PM EDT
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jul 22, 2013, 10:48 PM EDT
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 N144 reputationPosted Jul 22, 2013, 10:56 PM EDT
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jul 22, 2013, 11:02 PM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 22, 2013, 11:03 PM EDT
Regards,
Iftikar
Manj N144 reputationPosted Jul 22, 2013, 11:09 PM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 22, 2013, 11:13 PM EDT
Regards,
Iftikar
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jul 22, 2013, 11:19 PM EDT
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.
Manj N144 reputationPosted Jul 26, 2013, 8:59 PM EDT
can you tell me, which book is good to learn c# programming and sql .