C # VS2005 Синтаксическая ошибка (отсутствует оператор) в выражении запроса

Я использую VS2005 C # и SQL Server 2005. В настоящее время я выполняю импорт данных файла Excel .CSV в свою базу данных SQL Server. .

У меня возникла ошибка, которая, как я полагаю, связана с моим оператором sql. Ниже приведен мой код:

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>");
    }

Я получаю сообщение об ошибке

«Синтаксическая ошибка (отсутствует оператор) в выражении запроса '[Описание] FROM20111109164041.csv» ».

при выполнении с использованием (DbDataReader dr = ExcelCommand.ExecuteReader ()). Описание - последний столбец в моей базе данных.

Кто-нибудь знает, что не так с моим кодом? Спасибо

enter image description here

0
задан CodeCaster 9 November 2011 в 09:22
поделиться