Solved

.NET SQLCe Exporting Table Data

Posted on 2003-10-24
4
671 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
ID: 9620275
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
ID: 9899409
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
ID: 9909458
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
ID: 33910996
Well wanna share what web service you used? That sure would help me!
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

803 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