473,725 Members | 2,251 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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");
SqlCeDataAdapte r daCustomers = new SqlCeDataAdapte r();
SqlCeDataAdapte r daShipTos = new SqlCeDataAdapte r();
SqlCeDataAdapte r daItems = new SqlCeDataAdapte r();

//instantiate SqlCe SELECT command
SqlCeCommand SqlCeCmdCustome rs = new SqlCeCommand("S ELECT * FROM vmi_cust
WHERE 1 = 2", conn);
SqlCeCommand SqlCeCmdShipTo = new SqlCeCommand("S ELECT * FROM vmi_ship
WHERE 1 = 2", conn);
SqlCeCommand SqlCeCmdItems = new SqlCeCommand("S ELECT * 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.Tabl es[0].Rows.Count][];

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

//Create Dataset to get the results of the GetShipTosAndIt emsSyncData
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.Sel ectCommand = SqlCeCmdCustome rs;
daShipTos.Selec tCommand = SqlCeCmdShipTo;
daItems.SelectC ommand = SqlCeCmdItems;

//fill the data adapter's schema with that of the table in the dataset
daCustomers.Fil lSchema(dsRetCu stItems,SchemaT ype.Mapped, "vmi_cust") ;
daShipTos.FillS chema(dsRetCust Items,SchemaTyp e.Mapped, "vmi_ship") ;
daItems.FillSch ema(dsRetCustIt ems,SchemaType. Mapped, "vmi_item_maste r");

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

daCustomers.Mis singMappingActi on = MissingMappingA ction.Passthrou gh;
daShipTos.Missi ngMappingAction = MissingMappingA ction.Passthrou gh;
daItems.Missing MappingAction = MissingMappingA ction.Passthrou gh;

//seems this is needed to force the insert command to be assigned.
daCustomers.Ins ertCommand = cbCustomers.Get InsertCommand() ;
daShipTos.Inser tCommand = cbShipTos.GetIn sertCommand();
daItems.InsertC ommand = cbItems.GetInse rtCommand();

//call update to move all the data from sampletable DataTable into the
database table
daCustomers.Upd ate(dsRetCustIt ems, "VMI_CUST") ;
daShipTos.Updat e(dsRetCustItem s, "VMI_SHIP") ;
daItems.Update( dsRetCustItems, "VMI_ITEM_MASTE R");

cbCustomers.Dis pose();
cbShipTos.Dispo se();
cbItems.Dispose ();
}
catch(SqlCeExce ption SqlCeex)
{
MessageBox.Show ("Error insert/updating SqlCe database: " +
SqlCeex.Message );
}
catch(Exception ex)
{
MessageBox.Show ("Error in syncronization process: " + ex.Message);
}
finally
{
daCustomers.Dis pose();
daShipTos.Dispo se();
daItems.Dispose ();
SqlCeCmdCustome rs.Dispose();
SqlCeCmdShipTo. Dispose();
SqlCeCmdItems.D ispose();
conn.Close();
conn.Dispose();
}
}
Aug 13 '06 #1
0 3890

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

Similar topics

5
2034
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 one row, all of them were updated so i immediatelly figured out that i have to include the id of every entry in the update statement. This is where the problem is raised. My database is an Access database. The table i am updating contains a Date...
0
2362
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 document has nodes, and I would like to have a generic tool (I need to import about 35 tables). I'm trying something below:
10
5673
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) DsStudentCourse1.AcceptChanges() i'm also wondering because w/ out AcceptChanges the data is still save into the database and it is now faster.
14
2128
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 grid and write to the database and I set the new Primary Keys and related Fields to the new asigned atuonumbers in the Access.
4
2372
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 two fields: a primary key and another holding a string. In table B there are three fields: a primary key, a foreign key (which links to the primary key in A) and other field holding a string.
5
4747
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. Where is? Sqlce is not installed by default? Thanks
0
1699
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 the IDE that pulls data from two tables using an . The idea is to display the associated with the field. Because an is used, the IDE couldn’t auto-generate the Insert command, update command, or Delete command. 2. As a result, it was suggested...
0
1082
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 as far as I know. The SQL Server template seems easily adaptable to the sqlce, but before starting generating a new template I would like to ask you if there is a SQLCe specific template somewhere.
1
2373
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 need updating with 'CLOSED' where necessary.) I have been trying to use the OLEDB command builder to build the statement to update the database however it is returning an error whenever I try to do this. I already have a dataset full of data, 1...
0
8889
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9116
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8099
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6702
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4519
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4784
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3228
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2637
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2157
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.