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

  • SEARCH
  • Home
  • 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 9030349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:28:06+00:00 2026-06-16T07:28:06+00:00

I am working on access but stuck in insert queries having date time. like

  • 0

I am working on access but stuck in insert queries having date time. like these queries doesn’t work for me.

INSERT INTO tbl_fuel_levels([genset_id], [rec_time], [fuel_level], 
[grid_electricity], [genset_electricity], [genset_number]) 
VALUES('001', '#12/12/23 18:46:38+20#', '0', 'T', 'F', '+923468280124');

INSERT INTO tbl_fuel_levels([genset_id], [rec_time], [fuel_level], 
[grid_electricity], [genset_electricity], [genset_number]) 
VALUES('001', #'12/12/23 18:46:38+20'#, '0', 'T', 'F', '+923468280124');

INSERT INTO tbl_fuel_levels([genset_id], [rec_time], [fuel_level], 
[grid_electricity], [genset_electricity], [genset_number]) 
VALUES('001', '12/12/23 18:46:38+20', '0', 'T', 'F', '+923468280124');

enter image description here

Any idea? what could be wrong.

Here is my code in c#:

con = new OleDbConnection(ConnStr);
con.Open();

cmd = con.CreateCommand();
cmd.CommandText = "INSERT INTO tbl_fuel_levels([genset_id], [rec_time], 
[fuel_level], [grid_electricity], [genset_electricity], [genset_number]) 
VALUES('" + genset_id + "', '" + rec_time + "', '" + fuel_level + "', '" +
grid_electricity + "', '" + genset_electricity + "', '" + genset_number + "');";
cmd.ExecuteNonQuery();

I have also tried this.

cmd.CommandText = "INSERT INTO tbl_fuel_levels([genset_id], [rec_time], 
[fuel_level], [grid_electricity], [genset_electricity], [genset_number]) 
VALUES('" + genset_id + "', @rec_t, '" + fuel_level + "', '" + grid_electricity 
+ "','" + genset_electricity + "', '" + genset_number + "');";
cmd.Parameters.Add("@rec_t", OleDbType.DBTimeStamp).Value 
                              = DateTime.Parse(rec_time);

All other insert and select queries are working fine

  • 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-16T07:28:07+00:00Added an answer on June 16, 2026 at 7:28 am

    Your INSERT query has more than one problem. I copied this version from your comment to DJ:

    INSERT INTO tbl_fuel_levels (
        [genset_id],
        [rec_time],
        [fuel_level],
        [grid_electricity],
        [genset_electricity],
        [genset_number]
        )
    VALUES (
        '001',
        '#12/11/2023 2:46:38 PM#',
        '0',
        'T',
        'F',
        '+923468280124'
        );
    

    The problems are:

    1. You’re attempting to insert the string, '#12/11/2023 2:46:38 PM#' into the Date/Time field rec_time. Discard the single quotes to make that value a Date/Time literal instead of a string: #12/11/2023 2:46:38 PM#
    2. You’re attempting to insert the string, 'T' into the Yes/No field grid_electricity. Use True without quotes instead.
    3. You’re attempting to insert the string, 'F' into the Yes/No field genset_electricity. This is the same issue as problem #2. Use False without quotes.

    Use Access’ query designer to create a new query. Switch it to SQL View and paste in this statement:

    INSERT INTO tbl_fuel_levels (
        [genset_id],
        [rec_time],
        [fuel_level],
        [grid_electricity],
        [genset_electricity],
        [genset_number]
        )
    VALUES (
        '001',
        #12/11/2023 2:46:38 PM#,
        '0',
        True,
        False,
        '+923468280124'
        );
    

    If there are any remaining problems with that statement, work them out in Access before bothering with the c# code to create the statement.

    Or better, use the parameters query approach. Maybe you can get that working once you resolve those issues with the Yes/No fields.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Working with MS Access for the first time and coming across a few problems
I'm working with xslt for the first time. I have 2.0, but that's about
I feel like this should be really really simple, but I'm completely stuck! In
I've got a legacy program, and I'm working with Access 97. I want to
I'm working on managing access for users to some pages on my site. I
I am working on an Access adp that has its data stored in sql-server.
I am working on a database access layer project and decided to use Linq
I'm working on a Microsoft Access application for a summer camp to track which
I'm working on an algorithm which needs very fast random access to video frames
I'm working on a Python server application using SQLAlchemy for database access. I would

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.