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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:39:36+00:00 2026-06-14T17:39:36+00:00

I have to insert values in the table using insert query…the table stored in

  • 0

I have to insert values in the table using insert query…the table stored in the database has 3 columns: 1. Date (DateTime) 2. SensorValue (Float) 3. Difference (Float)
Now the values for each column comes from datagridview…..here is the button’s code for inserting

con.ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\dbsave.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
if (con.State == ConnectionState.Closed)
{
    con.Open();
}
for (Int32 i = 0; i < dataGridView1.Rows.Count-1; i++)
{
    String query1 = 
        "INSERT INTO " + tbName + 
        " ( Date, SensorValue, Difference) " + "VALUES (" +     
        dataGridView1.Rows[i].Cells[0].Value + "," + 
        dataGridView1.Rows[i].Cells[1].Value + "," + 
        dataGridView1.Rows[i].Cells[2].Value + ")";
    SqlCommand cmd1 = new SqlCommand(query1, con);
    cmd1.ExecuteNonQuery();
}
con.Close();
MessageBox.Show("The table has been saved");

The error is ofcourse in execution of the query….the first entry in the date column is the value: 12/05/2012 14:32:00….so basically the sql is not accepting the colon that is placed with 14….how can i solve this problem ? please help

  • 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-14T17:39:37+00:00Added an answer on June 14, 2026 at 5:39 pm

    update your query and add apostrophes:

    String query1 = 
        "INSERT INTO " + tbName + 
        " ( Date, SensorValue, Difference) " + "VALUES ('" +     
        dataGridView1.Rows[i].Cells[0].Value + "'," + 
        dataGridView1.Rows[i].Cells[1].Value + "," + 
        dataGridView1.Rows[i].Cells[2].Value + ")";
    SqlCommand cmd1 = new SqlCommand(query1, con);
    

    But I agree with Liath, parameters are more safe.

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

Sidebar

Related Questions

I have the following query in VBA: DoCmd.RunSQL INSERT INTO table (value) VALUES ('example')
I have the following query: INSERT INTO table (a, b, c) VALUES (NOW(), NOW()
I have this form which can insert/update values into database table. <div id=settingsdiv style=width:350px;
I have been able to manually insert values in my table using phpmyadmin, and
I have to insert the values in the table named First, but before inserting
I have the following table: I want to insert values from the MySQL workbench.
I have some problem whith such mysql_query INSERT INTO table VALUES ('', CURDATE()-1) why
I have a multi-row insert that looks something like: insert into table VALUES (1,
I have the following Python code: cursor.execute("INSERT INTO table VALUES var1, var2, var3,") where
I have the following code: <? $query =$db->prepare(INSERT INTO a_table (id, a_field) VALUES ('',

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.