uploading csv file

uploading csv file with double quote to sql server database

Page 1 of 1

6 Replies - 1748 Views - Last Post: 04 September 2010 - 12:58 AM Rate Topic: -----

#1 Amaka123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 03-June 10

uploading csv file

Posted 29 August 2010 - 08:34 PM

i really need an urgent help, stuck with writing cod to import csv file with double quote into sql server database, can someone help me am a newbie in programming
Is This A Good Question/Topic? 0
  • +

Replies To: uploading csv file

#2 MentalFloss  Icon User is offline

  • "ADDICTED"[2:5]
  • member icon

Reputation: 528
  • View blog
  • Posts: 1,397
  • Joined: 02-September 09

Re: uploading csv file

Posted 29 August 2010 - 10:33 PM

If you're using Microsoft Sql Server, there's the data import tool. There's no programming required. You just have to map the file correctly to the correct columns.
Was This Post Helpful? 0
  • +
  • -

#3 Amaka123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 03-June 10

Re: uploading csv file

Posted 31 August 2010 - 06:44 PM

I have use some of the tools like ssis, bulk insert, openrowset and they all give me errors resuling from the double quote complication in the CSv file. can u help me with codes to overcome the double quote and import the fie to sql server database
Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6107
  • View blog
  • Posts: 23,661
  • Joined: 23-August 08

Re: uploading csv file

Posted 31 August 2010 - 06:47 PM

Moved to Databases.

Note no one's likely to hand you code, if that's what you're expecting.
Was This Post Helpful? 0
  • +
  • -

#5 Amaka123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 03-June 10

Re: uploading csv file

Posted 01 September 2010 - 05:03 PM

The below is my code..can some one help me figure out why i cant upload the csv file;thanks

protected void Button1_Click(object sender, EventArgs e)
        {
            if (FileUpload1.HasFile)
            {
                FileInfo fileinfo = new FileInfo(FileUpload1.PostedFile.FileName);


                string strCsvFilePath = Server.MapPath("CSVFolder") + "\\" + fileinfo.Name;

                FileUpload1.SaveAs(strCsvFilePath);

                string strFilePath = Server.MapPath("CSVFolder");
                //DataTable csvTable = new DataTable("CSV_Data");
                SqlConnection dbConn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnString"].ToString());
                StreamReader sr = new StreamReader(strCsvFilePath);
                string csvDataconnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strCsvFilePath + ";"
              + "Extended Properties=" + "'text;HDR=Yes;FMT=Delimited'";

                {


                    OleDbConnection con = new OleDbConnection(csvDataconnectionString);
                    OleDbCommand cmd = new OleDbCommand(string.Format
                                                  ("SELECT * FROM [{0}]", strFilePath), con);

                    con.Open();

                    // Using a DataReader to process the data
                    OleDbDataReader reader = cmd.ExecuteReader();
                    SqlBulkCopy bc = new SqlBulkCopy(dbConn);
                    bc.DestinationTableName = "CSV_Data";

                    //bc.BatchSize = csvTable.Rows.Count;

                    dbConn.Open();

                    while (reader.Read())
                    {
                        bc.WriteToServer(reader);
                    }

                    dbConn.Close();
                    bc.Close();
                }
            }
        }
    }
}


MOD EDIT: When posting code...USE CODE TAGS!!!

:code:

This post has been edited by JackOfAllTrades: 03 September 2010 - 04:38 AM
Reason for edit:: Added code tags

Was This Post Helpful? 0
  • +
  • -

#6 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6107
  • View blog
  • Posts: 23,661
  • Joined: 23-August 08

Re: uploading csv file

Posted 03 September 2010 - 04:40 AM

OK, now we have code, so I guess I'll move this to C#.

Please tell us what exactly is the problem you are having...any errors? How does the result differ from what you expect?
Was This Post Helpful? 0
  • +
  • -

#7 Ionut  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 385
  • View blog
  • Posts: 1,057
  • Joined: 17-July 10

Re: uploading csv file

Posted 04 September 2010 - 12:58 AM

Quote

they all give me errors resuling from the double quote complication in the CSv file


Can you give an example of such complication? Can you attach the CSV file?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1