Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8293505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:50:57+00:00 2026-06-08T13:50:57+00:00

I was able to insert TIMESTAMP as a string into my table, but when

  • 0

I was able to insert TIMESTAMP as a string into my table, but when I read it out my program raises an error saying “String was not recognized as a valid DateTime.”

Here is how I insert my values into the table.

sqlstr := 'INSERT INTO ALARMS (ALARMTIME) VALUES ("'+DateTime.Now.ToString+'");';
cnn := new SQLiteConnection('Data Source=AlarmLog.s3db');
cnn.Open;
var mycommand := new SQLiteCommand(cnn);
mycommand.CommandText := sqlstr;
var info := mycommand.ExecuteNonQuery;
cnn.Close;

Here is how I read it out.

    sqlstr := 'SELECT * from ALARMS';
    var dt := new DataTable;
    cnn := new SQLiteConnection('Data Source=AlarmLog.s3db');
    cnn.Open;
    var mycommand := new SQLiteCommand(cnn);
    mycommand.CommandText := sqlstr;
    var reader := mycommand.ExecuteReader;
    dt.Load(reader); <---------------------Here is where I am getting the error, "String was not recognized as a valid DateTime."
    reader.Close;
    cnn.Close;

I know why I am getting the error, but why can’t I insert the TIMESTAMP as a date and time instead of string or text type. If you notice in my SQL query, I have quotation marks around the DateTime.Now.ToString statement. That’s the only way it accepts my SQL Statement.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T13:51:00+00:00Added an answer on June 8, 2026 at 1:51 pm

    Pass a date format that SQLite recognizes, like:

    DateTime.Now.ToString("yyyy-MM-ddTHH:mm")
    

    Other valid formats on this SQLite manual page.

    Even better is to use a parameter, like:

    sqlstr := 'INSERT INTO ALARMS (ALARMTIME) VALUES ($dt);';
    ...
    mycommand.Parameters.AddWithValue("$dt", DateTime.Now);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was not able to insert data into table with computed column using Subsonic.
I am not able to insert data into my table anymore! Here's my table
I'd like to be able to insert some values into a table using a
Not able to store all binary data values into sqlite3 table using QT. For
I'm using Qwebkit and I like to be able to insert into html table
I need to be able to insert numbers like 098532 into my table. This
I want to insert data into the postgresql database of OpenERP, I am able
I just need to be able to insert a key/value pair into an object
I want to be able to insert data into t1 and have data get
I'm not able to insert data to a field of type xml. looks like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.