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 6089445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:06:04+00:00 2026-05-23T12:06:04+00:00

I need some help with creating an insert statement for an Access 2007 database

  • 0

I need some help with creating an insert statement for an Access 2007 database using C# in VS2008. The current code that I have gives me “ERROR 42000: Syntax error in INSERT INTO statement.” I am not sure what is wrong. I wrote this code based on a working code that I used earlier this year that connected to an ms access table and transfer the database info into an oracle database.

Current code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Data.OracleClient;
using System.Data.SqlClient;
using System.IO;
using System.Data.Odbc;
class MainClass
{
static void Main(string[] args)
{
    string connectionString = "Dsn=Northwind 2007";
    string SQL = "SELECT * FROM Orders";
    string sqlins = "";
    OdbcConnection conn = new OdbcConnection(connectionString);

    OdbcCommand cmd = new OdbcCommand(SQL);
    cmd.Connection = conn;
    OdbcCommand cmdnon=new OdbcCommand(sqlins,conn);
    try
        {

        conn.Open();

        OdbcDataReader reader = cmd.ExecuteReader();
        while (reader.Read())
        {
            Console.Write("OrderID:" + reader.GetInt32(0).ToString());
            Console.Write(" ,");
            Console.WriteLine("Customer:" + reader.GetString(1).ToString());
            cmdnon.CommandText = "INSERT Commonstation ( S1Flow,S2Flow,S3Flow,S4Flow) VALUES (9999,999,999,999)";
            int rowsAffected = cmdnon.ExecuteNonQuery();
            Console.WriteLine(rowsAffected);
        }
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.InnerException.ToString());
    }
    finally
    {
        reader.Close();
        conn.Close();
    }
}
}

Working code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Data.OracleClient;
using System.Data.SqlClient;
using System.IO;
using System.Data.Odbc;


class GasReporter
{
    static void Primary( string[] args)
    {  
 string connectionString = "Dsn=Gas_meter";
        string col0 = "";
        string col1 = "";
        string col2 = "";
        string col3 = "";
        string col4 = "";
        string col5 = "";
        string col6 = "";
        string col7 = "";
        string col8 = "";
        string sqlins = "";
        string connString = "DSN=Gas_meter_proj;Uid=cm;Pwd=cmdev123";
        OdbcConnection conn = new OdbcConnection(connString);       
 try
{
        OdbcCommand cmdnon = new OdbcCommand(sqlins, conn);                            
        conn.Open();
        cmdnon.Parameters.Add(col0, OdbcType.DateTime);
        cmdnon.Parameters.Add(col1, OdbcType.Numeric);
        cmdnon.Parameters.Add(col2, OdbcType.Numeric);
        cmdnon.Parameters.Add(col3, OdbcType.Numeric);
        cmdnon.Parameters.Add(col4, OdbcType.Numeric);
        cmdnon.Parameters.Add(col5, OdbcType.Numeric);
        cmdnon.Parameters.Add(col6, OdbcType.Numeric);
        cmdnon.Parameters.Add(col7, OdbcType.Numeric);
        cmdnon.Parameters.Add(col8, OdbcType.Numeric);

                    OdbcConnection DbConnection = new OdbcConnection(connectionString);
                    OdbcCommand DbCommand = DbConnection.CreateCommand();
                    DbConnection.Open();
                    DbCommand.CommandText = "SELECT DateTime, S1Flow, S2Flow, S3Flow, S4Flow, S1FlowTotal, S2FlowTotal, S3FlowTotal, S4FlowTotal FROM CommonStation WHERE Format(DateTime, 'mm/dd/yyyy') >=(select Format(max(DateTime),'mm/dd/yyyy') from CommonStation)";
                    OdbcDataReader DbReader = DbCommand.ExecuteReader();
                    int fCount = DbReader.FieldCount;

                   while (DbReader.Read())
                    {
                        col0 = DbReader["DateTime"].ToString();
                        col1 = DbReader["S1Flow"].ToString();
                        col2 = DbReader["S2Flow"].ToString();
                        col3 = DbReader["S3Flow"].ToString();
                        col4 = DbReader["S4Flow"].ToString();
                        col5 = DbReader["S1FlowTotal"].ToString();
                        col6 = DbReader["S2FlowTotal"].ToString();
                        col7 = DbReader["S3FlowTotal"].ToString();
                        col8 = DbReader["S4FlowTotal"].ToString();
                        cmdnon.CommandText="insert into Commonstation(CommStatDate_Time, S1_Flow, S2_Flow, S3_Flow, S4_Flow, S1_Flow_Total, S2_Flow_Total, S3_Flow_Total, S4_Flow_Total ) values (to_date('" + col0 + "', 'MM/DD/YYYY HH:MI:SS AM' ),to_number('" + col1 + "'), to_number('" + col2 + "'), to_number('" + col3 + "'), to_number('" + col4 + "'),to_number('" + col5 + "'),to_number('" + col6 + "'),to_number('" + col7 + "'),to_number('" + col8 + "'))";
                        int rowsAffected = cmdnon.ExecuteNonQuery(); 
                        Console.WriteLine(rowsAffected);
                    }
                }
                catch (Exception ex)
                {
                     ex.InnerException.ToString()+")");                                              
 }
    finally
                {
                    conn.Close();
                    DbReader.Close();
                    DbCommand.Dispose();
                    DbConnection.Close();
                }

    }

}
  • 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-05-23T12:06:04+00:00Added an answer on May 23, 2026 at 12:06 pm

    Try:

    cmdnon.CommandText = "INSERT INTO Commonstation...
    

    At least, that’s what the error is telling you.

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

Sidebar

Related Questions

Ok need some help, I have a system I'm creating that will allow users
I need some help in creating report using iReport for this layout. I am
I need some help from the shell-script gurus out there. I have a .txt
Hi I need some help with the following scenario in php. I have a
I am new to all the anonymous features and need some help. I have
I'm working with jQuery for the first time and need some help. I have
I've gone through most of the example code and I still need some help.
I need some help creating this extension method. My view inherits from <%@ Page
I need some help tweaking this php code to print out a default value
I have real trouble understanding mod_rewrite, and got some help in creating a RewriteRule

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.