Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

.NET SQLCe Exporting Table Data

Posted on 2003-10-24
4
Medium Priority
?
681 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 640 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

926 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