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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:26:18+00:00 2026-06-15T02:26:18+00:00

Hi im unsing Oledb to insert data to an excel sheet from multiple textboxes.

  • 0

Hi im unsing Oledb to insert data to an excel sheet from multiple textboxes. The issue i have is that it is not going into excel as a number type but string, so a grpah can no be automated off the date.
How would i insert values into excel as number type? ive tried converting the textboxes to int with no luck.

My code is as below.

 string szConn = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=L://Metrics_gen.xlsx;Extended Properties='Excel 8.0;HDR=YES;'";
            OleDbConnection conn = new OleDbConnection(szConn);
            int v1 = Convert.ToInt32(textBox1.Text);
            int v2 = Convert.ToInt32(textBox2.Text);
            int v3 = Convert.ToInt32(textBox3.Text);
            int v4 = Convert.ToInt32(textBox4.Text);
            int v5 = Convert.ToInt32(textBox5.Text);


            conn.Open();
            OleDbCommand cmd = new OleDbCommand("INSERT INTO [Sheet1$]([Total],[Closed],[Issues],[Cancelled],[Back out]) VALUES('" + v1 + "','" + v2 + "','" + v3 + "','" + v4 + "','" + v5 + "')", conn);
            cmd.ExecuteNonQuery();


            conn.Close();
            MessageBox.Show("complete");
  • 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-15T02:26:19+00:00Added an answer on June 15, 2026 at 2:26 am

    The problem is that you are converting your integers into string literals when constructing the insert command. See below:

    OleDbCommand cmd = new OleDbCommand("INSERT INTO [Sheet1$]([Total],[Closed],[Issues],[Cancelled],[Back out]) VALUES('" + v1 + "','" + v2 + "','" + v3 + "','" + v4 + "','" + v5 + "')", conn);
    

    Change that line into:

    OleDbCommand cmd = new OleDbCommand("INSERT INTO [Sheet1$]([Total],[Closed],[Issues],[Cancelled],[Back out]) VALUES(" + v1 + "," + v2 + "," + v3 + "," + v4 + "," + v5 + ")", conn);
    

    This should solve all your problems 🙂

    Note: Constructing SQL by hand is error prone. Integers are the least of your worries. Imagine trying to inserting a string which happens to contain the single quotation mark character (‘), a float when you have set your culture to one with comma as the decimals separator, a date and so on and so forth. Personally, I prefer using libraries such as EPPlus (XLSX) and ExcelLibrary (XLS). Both are LGPL licensed and give you greater flexibility than the method you are currently using. They do not require Excel to be installed on the machine which makes them ideal for server-side Excel report generation. Moreover they help avoid the various memory leak problems solutions using Microsoft Office Interop often come with.

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

Sidebar

Related Questions

I am using this: insert into bla select * FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;HDR=YES;Database=c:\bla.xls', 'select
I am using SSIS to do data transformation from excel to OLEDB SQL. I
I am using OLEDB to INSERT INTO an existing Excel worksheet. But I want
I am trying to retieve data from a MySQL table and insert into a
I need to programmatically insert a row into an Excel Spreadsheet multiple times. I
i am preparing myself for importing data from excel sheet to sql server 2005.I
How can i export my data from SQL server 2008 into Excel 2010 or
I'd like to insert a new row of data into my oledb. I simply
I am using OLEDB to Update data in .dbf database from c#. I get
I have a query being created using OLEDB from access and need to get

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.