Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

.NET SQLCe Exporting Table Data

Posted on 2003-10-24
4
Medium Priority
?
680 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

721 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