Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Errors with Export to CSV From DB

Errors with Export to CSV From DB

Scheduled Pinned Locked Moved C#
databasehelpquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MumbleB
    wrote on last edited by
    #1

    Hi Guys. I have managed to get some code to export data in my Access DB to a CSV file. Now, I have two small issues. 1. I want to mark all the records as they are exported to Y in a column named exported and only export all the records marked as N. Anybody have a suggestion on how I could do this in the export code? 2. When I open the CSV file in Excel I get a few errors. First error says that the file is in a different format than the one specified by the extention. It allows you to continue and then comes up with error "Cannot read the 1st record. The it reports yet another error which says that Excel has determined the file to be a SYLK file but not load it" but it still imports the data into Excel. Any ideas on how I get past this? Code below:

        private void toolStripButton2\_Click(object sender, EventArgs e)
        {
            
            StreamWriter sw = new StreamWriter(@"C:\\nefz.csv", false);
            DataTable dt = m\_dtCallCentre;
            int iColCount = dt.Columns.Count;
            for (int i = 0; i < iColCount; i++)
            {
                sw.Write(dt.Columns\[i\]);
                if (i < iColCount - 1)
                {
                    sw.Write(";");
                }
            }
            sw.Write(sw.NewLine);
            foreach (DataRow dr in dt.Rows)
            {
                for (int i = 0; i < iColCount; i++)
                {
                    if (!Convert.IsDBNull(dr\[i\]))
                    {
                        sw.Write(dr\[i\].ToString());
                    }
                    if (i < iColCount - 1)
                    {
                        sw.Write(";");
                    }
                }
                sw.Write(sw.NewLine);
            }
            sw.Close();
    
        }
    
    B 1 Reply Last reply
    0
    • M MumbleB

      Hi Guys. I have managed to get some code to export data in my Access DB to a CSV file. Now, I have two small issues. 1. I want to mark all the records as they are exported to Y in a column named exported and only export all the records marked as N. Anybody have a suggestion on how I could do this in the export code? 2. When I open the CSV file in Excel I get a few errors. First error says that the file is in a different format than the one specified by the extention. It allows you to continue and then comes up with error "Cannot read the 1st record. The it reports yet another error which says that Excel has determined the file to be a SYLK file but not load it" but it still imports the data into Excel. Any ideas on how I get past this? Code below:

          private void toolStripButton2\_Click(object sender, EventArgs e)
          {
              
              StreamWriter sw = new StreamWriter(@"C:\\nefz.csv", false);
              DataTable dt = m\_dtCallCentre;
              int iColCount = dt.Columns.Count;
              for (int i = 0; i < iColCount; i++)
              {
                  sw.Write(dt.Columns\[i\]);
                  if (i < iColCount - 1)
                  {
                      sw.Write(";");
                  }
              }
              sw.Write(sw.NewLine);
              foreach (DataRow dr in dt.Rows)
              {
                  for (int i = 0; i < iColCount; i++)
                  {
                      if (!Convert.IsDBNull(dr\[i\]))
                      {
                          sw.Write(dr\[i\].ToString());
                      }
                      if (i < iColCount - 1)
                      {
                          sw.Write(";");
                      }
                  }
                  sw.Write(sw.NewLine);
              }
              sw.Close();
      
          }
      
      B Offline
      B Offline
      Bino B
      wrote on last edited by
      #2

      u can manually xport the data in MDB as CSV, from import/export option in MS Access. And i guess from there u can update the coluns to y/n thru ur application.

      Cheers Bino www.codepal.co.nr

      M 1 Reply Last reply
      0
      • B Bino B

        u can manually xport the data in MDB as CSV, from import/export option in MS Access. And i guess from there u can update the coluns to y/n thru ur application.

        Cheers Bino www.codepal.co.nr

        M Offline
        M Offline
        MumbleB
        wrote on last edited by
        #3

        Yeah, I guess I can do that but that is not what I want to do. I want to do the export through code. This will be done by a user once I get it to work. Anybody else able to help out maybe or suggest something?

        M 1 Reply Last reply
        0
        • M MumbleB

          Yeah, I guess I can do that but that is not what I want to do. I want to do the export through code. This will be done by a user once I get it to work. Anybody else able to help out maybe or suggest something?

          M Offline
          M Offline
          MumbleB
          wrote on last edited by
          #4

          Can anybody else please have a look at the Original post please?

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups