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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:59:34+00:00 2026-05-26T16:59:34+00:00

I am using VS2005 C# and SQL Server 2005. I am currently doing an

  • 0

I am using VS2005 C# and SQL Server 2005. I am currently doing an import for a .CSV excel file data into my SQL Server database.

I am having some error, which I assume is related to my sql statement. Below is my code:

protected void Button1_Click(object sender, EventArgs e)
    {
        if (FileUpload1.HasFile)
        {
            // Get the name of the Excel spreadsheet to upload. 
            string strFileName = Server.HtmlEncode(FileUpload1.FileName);

            // Get the extension of the Excel spreadsheet. 
            string strExtension = Path.GetExtension(strFileName);

            // Validate the file extension. 
            if (strExtension != ".xls" && strExtension != ".xlsx" && strExtension != ".csv" && strExtension != ".csv")
            {
                Response.Write("<script>alert('Failed to import DEM Conflicting Role Datasheet. Cause: Invalid Excel file.');</script>");
                return;
            }

            // Generate the file name to save. 
            string dir = @"C:\Documents and Settings\rhlim\My Documents\Visual Studio 2005\WebSites\SoD\UploadFiles\";
            string mycsv = DateTime.Now.ToString("yyyyMMddHHmmss") + strExtension;
            // Save the Excel spreadsheet on server. 
            FileUpload1.SaveAs(dir+mycsv);

            // Create Connection to Excel Workbook
            string connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + dir + ";Extended Properties=Text;";
            using (OleDbConnection ExcelConnection = new OleDbConnection(connStr))
            {
                OleDbCommand ExcelCommand = new OleDbCommand("SELECT [TABLES] FROM" + mycsv, ExcelConnection);

            OleDbDataAdapter ExcelAdapter = new OleDbDataAdapter(ExcelCommand);

            ExcelConnection.Open();

            using (DbDataReader dr = ExcelCommand.ExecuteReader())
            {
                // SQL Server Connection String
                string sqlConnectionString = "Data Source=<IP>;Initial Catalog=<DB>;User ID=<UID>;Password=<PW>";

                // Bulk Copy to SQL Server
                using (SqlBulkCopy bulkCopy =
                           new SqlBulkCopy(sqlConnectionString))
                {
                    bulkCopy.DestinationTableName = "DEMUserRoles";
                    bulkCopy.WriteToServer(dr);
                    Response.Write("<script>alert('DEM User Data imported');</script>");

                }
            }
            }
        }
        else Response.Write("<script>alert('Failed to import DEM User Roles Data. Cause: No file found.');</script>");
    }

I am getting the error

“Syntax error (missing operator) in query expression ‘[Description] FROM20111109164041.csv’.”

while executing using (DbDataReader dr = ExcelCommand.ExecuteReader()). Description is the last column in my database.

Anyone know what is wrong with my code? Thank You

enter image description here

  • 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-26T16:59:34+00:00Added an answer on May 26, 2026 at 4:59 pm

    You need a space between FROM and the csv file! 🙂

    OleDbCommand ExcelCommand = new OleDbCommand("SELECT [TABLES] FROM " + mycsv, ExcelConnection);
    

    That’s why I always use the string.Format method, you see much better how the final string will look:

    OleDbCommand ExcelCommand = new OleDbCommand(string.Format("SELECT [TABLES] FROM {0}",mycsv), ExcelConnection);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using VS2005 C# and SQL Server 2005. I have an Excel file
I am using C# VS2005 and SQL Server 2005. I have an Excel import
I am using VS2005 C# and SQL Server 2005. Currently I am able to
I am using VS2005 C# and SQL Server 2005. I am currently using user
I am using VS2005 and SQL Server 2005. I am trying to execute multiple
I am using VS2005 and SQL Server 2005. I am trying to execute multiple
I am using VS2005 C# and SQL Server 2005. I have a SQL Query
I want to extract all data from an Excel file to a SQL Server
I am using VS2005 C# and SQL Server 2005. I have a GridView and
I am using VS2005 C# and SQL Server 2005. I want to form an

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.