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
Solved

.NET SQLCe Exporting Table Data

Posted on 2003-10-24
4
675 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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Store results in vb.net 3 24
VB.NET 2008 Winforms Signing 13 31
C#.net split string and then check appropriate checkboxlist 4 26
MYSQL responding very slow 3 21
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.   …
The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

856 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