Android Question Problem Inserting Dates and Times

philwest

Member
Licensed User
Longtime User
Hey, I have been having a few problems inserting dates and times into my apps database submitted by the user:

The following lines are ok:

SQL1.ExecNonQuery("CREATE TABLE Event (Date INTEGER, Time1 INTEGER, Time2 INTEGER, Name TEXT, Desc TEXT)")

SQL1.ExecNonQuery("INSERT INTO Event VALUES(" & DateTime.DateParse("2015/01/01") & "," & DateTime.TimeParse("16:00") & " , " & DateTime.TimeParse("18:00") & " , 'Family' , 'sample description one')")

ListView1.AddSingleLine(DateTime.Date(Curs.GetLong("Date")))

ListView2.AddSingleLine(DateTime.Time(Curs.GetLong("Time1")))

However as soon as I get to this part of my program:

sumstring1 = EditText1.Text
sumstring2 = EditText2.Text
sumstring3 = EditText5.Text
sumstring4 = EditText6.Text

SQL1.ExecNonQuery("INSERT INTO Event VALUES(" & DateTime.DateParse(tempo1) & "," & DateTime.TimeParse(sumstring1) & " , " & DateTime.TimeParse(sumstring2) & " , " & sumstring3 & " , " & sumstring4 & ")")

I keep getting an error. I know the values are correct because I put the sumstring's in a label to view the input and the values appear correct. What am I doing wrong?
 

philwest

Member
Licensed User
Longtime User
Oh just to clarify, it is this line that is the problem specifically: SQL1.ExecNonQuery("INSERT INTO Event VALUES(" & DateTime.DateParse(tempo1) & "," & DateTime.TimeParse(sumstring1) & " , " & DateTime.TimeParse(sumstring2) & " , " & sumstring3 & " , " & sumstring4 & ")")

Getting the sumstrings work
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
You say you get an error, why don't you tell us what error ?
Try this:
SQL1.ExecNonQuery("INSERT INTO Event VALUES(" & DateTime.DateParse(tempo1) & "," & DateTime.TimeParse(sumstring1) & " , " & DateTime.TimeParse(sumstring2) & " , '" & sumstring3 & "' , '" & sumstring4 & "')")
You need quotes for text.
 
Upvote 0

Devan

Member
Licensed User
Longtime User
As per DonManfred advice pls, Use Log(Message) to identify what the exact problem happening inside the program command line. This has help me with a few complicated codes and commands.
Hopefully this helps you.
tq
 
Upvote 0
Top