Android Question Problem Inserting Dates and Times

Discussion in 'Android Questions' started by philwest, May 18, 2015.

  1. philwest

    philwest Member Licensed 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?
     
  2. philwest

    philwest Member Licensed 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
     
  3. klaus

    klaus Expert Licensed 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.
     
    Devan, DonManfred and Peter Simpson like this.
  4. Devan

    Devan Member Licensed 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
     
    DonManfred likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice