Saving Date from picker??
-
Hello, I am trying to save the date to a table from a date picker so that the next time the form is open it will have the last date picked which i will call form the table and assign it to the datepicker as the value. the problem i am having is that when i insert the date into the table which the field is formated to Date i get 12/30/1899 for every date that is inserted. Can someone tell me if there is an easier way to do this or how I Can fix this problem. below is the code i am using. Thanks, Santana 'delete old dates and Saves Dates to date table Dim startdate As Date Dim enddate As Date startdate = pkrstartdate.Text enddate = pkrenddate.Text datedap.DeleteCommand.CommandText = "Delete * From datetbl" datedap.DeleteCommand.ExecuteNonQuery() datedap.InsertCommand.CommandText = "Insert into datetbl (startdate,enddate) values (" & startdate & "," & enddate & ")" datedap.InsertCommand.ExecuteNonQuery() MsgBox(startdate) MsgBox(enddate) newMDRConn.Close()
-
Hello, I am trying to save the date to a table from a date picker so that the next time the form is open it will have the last date picked which i will call form the table and assign it to the datepicker as the value. the problem i am having is that when i insert the date into the table which the field is formated to Date i get 12/30/1899 for every date that is inserted. Can someone tell me if there is an easier way to do this or how I Can fix this problem. below is the code i am using. Thanks, Santana 'delete old dates and Saves Dates to date table Dim startdate As Date Dim enddate As Date startdate = pkrstartdate.Text enddate = pkrenddate.Text datedap.DeleteCommand.CommandText = "Delete * From datetbl" datedap.DeleteCommand.ExecuteNonQuery() datedap.InsertCommand.CommandText = "Insert into datetbl (startdate,enddate) values (" & startdate & "," & enddate & ")" datedap.InsertCommand.ExecuteNonQuery() MsgBox(startdate) MsgBox(enddate) newMDRConn.Close()
mariscal wrote: datedap.InsertCommand.CommandText = "Insert into datetbl (startdate,enddate) values (" & startdate & "," & enddate & ")" Stringing together an SQL statement like this is a bad idea. Instead, use a stored procedure that can validate what your putting into the table. This will also give you the ability to use SQLParameter objects that can properly convert the date to an SQL compatible DBDate and back again. RageInTheMachine9532