473,396 Members | 1,816 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Updating SqlCe Database from a DataSet

I have a PocketPC mobile application that gets its data from the Sql Server
database via a web service. The web service returns a dataset that I need to
load into the SqlCe database on the mobile device. I have a method to
perform this task but it doesn't load the data into the SqlCe database. The
data is downloaded into the dataset from the web service just fine but I
can't get the data into the SqlCe database. Any suggestions would be
appreciated!!!

Here's the method (I've reformatted it to fit better in the small window):

private void Syncronization()
{
SqlCeConnection conn = null;
conn = new SqlCeConnection ("Data Source = VMI.sdf");
SqlCeDataAdapter daCustomers = new SqlCeDataAdapter();
SqlCeDataAdapter daShipTos = new SqlCeDataAdapter();
SqlCeDataAdapter daItems = new SqlCeDataAdapter();

//instantiate SqlCe SELECT command
SqlCeCommand SqlCeCmdCustomers = new SqlCeCommand("SELECT * FROM vmi_cust
WHERE 1 = 2", conn);
SqlCeCommand SqlCeCmdShipTo = new SqlCeCommand("SELECT * FROM vmi_ship
WHERE 1 = 2", conn);
SqlCeCommand SqlCeCmdItems = new SqlCeCommand("SELECT * FROM
vmi_item_master WHERE 1 = 2", conn);
try
{
//Create an array and load all the ShipToID's into the array
string [][] arrayShipToID = new
string[dsVMI_Cust.Tables[0].Rows.Count][];

for(int x = 0; x < dsVMI_Cust.Tables[0].Rows.Count; x++)
{
arrayShipToID[x] = new string[] {
dsVMI_Cust.Tables[0].Rows[x]["ship2_id"].ToString(),
dsVMI_Cust.Tables[0].Rows[x]["is_existing_customer"].ToString()
};
}

//Create Dataset to get the results of the GetShipTosAndItemsSyncData
web service method
DataSet dsRetCustItems = new DataSet();

//Open the connection to the SqlCe database
conn.Open();

//Create SqlCe command object to store
//this is a way to get the schema from the database table, without
filling any data.
daCustomers.SelectCommand = SqlCeCmdCustomers;
daShipTos.SelectCommand = SqlCeCmdShipTo;
daItems.SelectCommand = SqlCeCmdItems;

//fill the data adapter's schema with that of the table in the dataset
daCustomers.FillSchema(dsRetCustItems,SchemaType.M apped, "vmi_cust");
daShipTos.FillSchema(dsRetCustItems,SchemaType.Map ped, "vmi_ship");
daItems.FillSchema(dsRetCustItems,SchemaType.Mappe d, "vmi_item_master");

//force the DataAdapter to generate the insert command, can also be manually
set.
SqlCeCommandBuilder cbCustomers = new SqlCeCommandBuilder(daCustomers);
SqlCeCommandBuilder cbShipTos = new SqlCeCommandBuilder(daShipTos);
SqlCeCommandBuilder cbItems = new SqlCeCommandBuilder(daItems);

daCustomers.MissingMappingAction = MissingMappingAction.Passthrough;
daShipTos.MissingMappingAction = MissingMappingAction.Passthrough;
daItems.MissingMappingAction = MissingMappingAction.Passthrough;

//seems this is needed to force the insert command to be assigned.
daCustomers.InsertCommand = cbCustomers.GetInsertCommand();
daShipTos.InsertCommand = cbShipTos.GetInsertCommand();
daItems.InsertCommand = cbItems.GetInsertCommand();

//call update to move all the data from sampletable DataTable into the
database table
daCustomers.Update(dsRetCustItems, "VMI_CUST");
daShipTos.Update(dsRetCustItems, "VMI_SHIP");
daItems.Update(dsRetCustItems, "VMI_ITEM_MASTER");

cbCustomers.Dispose();
cbShipTos.Dispose();
cbItems.Dispose();
}
catch(SqlCeException SqlCeex)
{
MessageBox.Show("Error insert/updating SqlCe database: " +
SqlCeex.Message);
}
catch(Exception ex)
{
MessageBox.Show("Error in syncronization process: " + ex.Message);
}
finally
{
daCustomers.Dispose();
daShipTos.Dispose();
daItems.Dispose();
SqlCeCmdCustomers.Dispose();
SqlCeCmdShipTo.Dispose();
SqlCeCmdItems.Dispose();
conn.Close();
conn.Dispose();
}
}
Aug 13 '06 #1
0 3870

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: junglist | last post by:
Hi guys, I've been trying to implement an editable datagrid and i have been succesful up to the point where i can update my datagrid row by row. However what used to happen was that once i updated...
0
by: Locusta | last post by:
Hello, I'm looking for a generic way to import XML documents into a local SQLCE database (on Pocket PC). To complicate, the local SQLCE database has more fields in the tables than the XML...
10
by: jaYPee | last post by:
does anyone experienced slowness when updating a dataset using AcceptChanges? when calling this code it takes many seconds to update the database SqlDataAdapter1.Update(DsStudentCourse1)...
14
by: Lars Netzel | last post by:
A little background: I use three Datagrids that are in a child parent relation. I Use Negative Autoincrement on the the DataTables and that's workning nice. My problem is when I Update these...
4
by: Geoff | last post by:
Hi I'm hoping somebody can help me with the following problem that has occurred to me. Suppose I have two tables in an SQL Server database. Let's call these tables A and B. Assume that A has...
5
by: Titeuf | last post by:
ok I start programming mobile application with VB.NET (VS 2005) I am interested work with Sqlce Also I look for add reference in my project I search "System.Data.SqlServerCe" but not found....
0
by: OldStd | last post by:
Updating data using 2 data sets I am having some problems in updating the database using two datasets as suggested by someone. 1. Data is displayed in a data grid from a dataset generated using...
0
by: dariosalvi78 | last post by:
Hi, I am trying to use MyGeneration with a SQLCe database in the Compact Framework 2 environment. My first problem now is that MyGeneration (its latest version) has no template for the SqlCe...
1
by: jonbartlam | last post by:
Hi There I'm not sure what exactly is going wrong here. I'm writing an application that retreives a table from a database (tbl_internalfaults) and updates it. (Actually, just the status column will...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.