Solved

.NET SQLCe Exporting Table Data

Posted on 2003-10-24
4
665 Views
Last Modified: 2012-06-22
Hi, does anyone know how to export table data from SQLCe into a file?

Thanks.
0
Comment
Question by:SwitchStance
4 Comments
 
LVL 1

Expert Comment

by:LastResort
Comment Utility
You can persist a dataset with [DataSet].WriteXml([Filename]} type stuff. Persisting a table seems overly complex to me.
0
 

Accepted Solution

by:
lyptus earned 160 total points
Comment Utility
Here is code I used to write sqlce data to a text file
if (File.Exists("\\My Documents\\Orders.txt"))
{
     File.Delete("\\My Documents\\Orders.txt");
}
     try
      {
      FileStream myFileStream = File.Create("\\My Documents\\Orders.txt");
      StreamWriter writer = new StreamWriter(myFileStream);
                        
      SqlCeConnection cn = new SqlCeConnection(@"Data Source=\My Documents\Growth.sdf");
      cn.Open();
string SQL = "SELECT OrderID, CustomerID, EmployeeID, OrderDate, Paid, Method, Delivered, PaidDate, CheckNum From rdaOrdersErrors";
      SqlCeCommand cmd = new SqlCeCommand(SQL,cn);
      cmd.CommandType = CommandType.Text;
                        
                  
      SqlCeDataReader dtr = cmd.ExecuteReader( CommandBehavior.Default);
      while ( dtr.Read() )
      {
           writer.WriteLine("Order ID: " + dtr.GetInt64(0));
            //long orderid = (dtr.GetInt64(0));
            //writer.WriteLine(orderid);
            writer.WriteLine("Customer ID: " + dtr.GetInt32(1).ToString());
            //writer.WriteLine(dtr.GetInt32(1).ToString());
            writer.WriteLine("Employee ID: " + dtr.GetInt32(2).ToString());
            writer.WriteLine("Order Date: " + dtr.GetDateTime(3).ToShortDateString());
            writer.WriteLine("Paid: " + dtr.GetString(4));
            writer.WriteLine("Method: " + dtr.GetString(5));
            writer.WriteLine("Delivered: " + dtr.GetString(6));
            writer.WriteLine("Paid Date: " + dtr.GetDateTime(7).ToShortDateString());
            writer.WriteLine("Check Num: " + dtr.GetInt32(8).ToString());
                              
      }
      cn.Close();
      writer.Close();
      }
      catch (IOException ioe)
      {
               MessageBox.Show("IO Exception: " + ioe.ToString());
      }
Hope this helps
0
 

Author Comment

by:SwitchStance
Comment Utility
lyptus, thanks for the reply. However, it came a little too late. I used a web-service to export each line of data and just left this question open in case someone came up with a better way.

Thanks for sharing.
0
 
LVL 5

Expert Comment

by:LarcenIII
Comment Utility
Well wanna share what web service you used? That sure would help me!
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now