Content by Category
.NET 1.x
.NET 2.0
.NET 3.0
.NET 3.5
.NET 4.0
.NET 4.5
.NET Assemblies
.NET Framework
.NET Getting Started
Accessibility
ADO.NET
Advertorials
Agile Development
AJAX
Amazon Web Services
Analysis Services
Android
Architecture
Arduino
ASP .NET Web API
ASP.NET
ASP.NET MVC
ASP.NET WebForms
Azure
B2B (Business Integration)
BDD
Big Data
Bing
BizTalk
Book Excerpts
Build and Deploy
Business Intelligence
C#
C++
ClickOnce
Cloud Computing
Code Contracts
CODE Framework Info - non Technical
CODE on the Road!
COM+
Community
Conferences
Continuous Integration
Crystal Reports
CSLA.NET
CSS
Data
Debugger
Design Patterns
Development Process
Display Technologies
Distributed Computing
Document Database
DotNetNuke
DSL
Dynamic Languages
Dynamic Programming
Editorials
Enterprise Services ("COM+")
Entity Framework
Events
Expression Blend
F#
Fox to Fox
Frameworks
Functional Programming
Git
Graphics
HTML 5
Internet Explorer 8.0
Interviews
IOS
iPhone
Iron Ruby
Java
Java Script
JavaScript
jQuery
JSON
Lightswitch
LINQ
Linux
LUA
Mac OS X
MDX
Messaging
Metro
Microsoft Application Blocks
Microsoft Business Rules Framework
Microsoft Dynamics
Microsoft Expression
Microsoft Office
Mobile Development
Mobile PC
Mono
MsBuild
MVVM
MySQL
Network
NHibernate
node.js
NOSQL
Nuget
Object Oriented Development
Objective C
Odata
OLAP
Open Source
Opinion
Opinions
Oracle
ORM
Other Languages
Parallel Programming
Patterns
PHP
Podcasts
Post Mortem
PowerPoint
Print/Output
Prism
Product News
Product Reviews
Project Management
Prolog
Python
Q&A
Rails
Rake
Razor
Reporting Services
REST
RIA Services
Ruby
Ruby on Rails
Scheme
Search
Security
Services
SharePoint
SignalR
Silverlight
SOA
Social Networks
Software & Law
Software Business
Source Control
Speech-Enabled Applications
SQL Server
SQL Server 2000
SQL Server 2005
SQL Server 2008
SQL Server 2012
SQL Server CE/AnyWhere/Mobile/Compact
SSIS
Subversion
Sync Framework
Tablet PC
TDD
Team System
Techniques
Testing and Quality Control
TFS
Tips
TypeScript
UI Design
UML
User Groups
VB Script
VB.NET
Version Control
VFP and .NET
VFP and SQL Server
Virtual Earth
Vista
Visual Basic
Visual Basic 6 (and older)
Visual FoxPro
Visual Studio .NET
Visual Studio 11
Visual Studio 2005
Visual Studio 2008
Visual Studio 2010
Visual Studio 2011
Visual Studio 2012
Visual Studio Tools for Office
VSX
WCF
Web Development (general)
Web Services
WebMatrix
WF
Whitepapers
Windows 7
Windows 8
Windows Azure
Windows Live
Windows Phone 7
Windows Phone SDK
Windows Server
Windows Vista
WinForms
WinRT
Workflow
WPF
XAML
Xiine Documentation
XML
XNA
XSLT



Component One


LearnNow
 


Component One

Reader rating:
Click here to read 1 comment about this article.
Article source: CoDe (2004 - January/February)


Article Pages: < Previous - 1  2 


Waiting to Inhale (Cont.)

Secretary of RowState

I have never been a big fan of transmitting DataSets via Web services because they tend to be pretty bloated. I prefer to send arrays of entity classes via .NET Remoting. However, I had a client recently that wanted to use the batch updating feature of DataSets on a PocketPC device using the .NET Compact Framework. For various reasons (most notably feature lock in, configuration, and security issues) they wanted to avoid using Remote Data Access (RDA) and Merge Replication to get data from their Web service (the .NET CF doesn't support Remoting) into SQL Server CE on a PDA.

What I needed to do to get this process working optimally was change the RowState property of each DataRow object to DataRowState.Added inside the Web service before I sent it over the wire to the PocketPC device, so that all it had to do was use a SqlDataAdapter object and a SqlCommandBuilder object to batch insert the contents of the DataSet into SQL Server CE. Unfortunately, the RowState property of the DataRow class is read only, so I had to get a bit creative.

I came up with two approaches that accomplish what I needed. The first was to serialize the DataSet to an XML string, manually insert the HasChanges="inserted" DiffGram hint using string manipulation, then deserialize the string back into a DataSet object:

//...load DataSet into variable ?ds?...//

XmlSerializer serializer = 
new XmlSerializer(typeof(DataSet));
MemoryStream ms = new MemoryStream();
serializer.Serialize(ms,ds);
string xml = 
Encoding.ASCII.GetString(ms.ToArray());
ms.Close();
xml = xml.Replace("<Table","<Table 
diffgr:hasChanges=\"inserted\"");
ds = (DataSet)serializer.Deserialize(new 
MemoryStream(Encoding.ASCII.GetBytes(xml)));

The approach above worked relatively well, but since serialization requires Reflection, and a host of other "not so speedy" processes, I sought out a faster solution that was less of a "hack." The approach below is nearly three times as fast as the serialization example:

//...load DataSet into variable ?ds?...//

ds2 = ds.Clone();

for(int i=0;i<ds.Tables[0].Rows.Count;i++)
{
ds2.Tables[0].Rows.Add(
ds.Tables[0].Rows[i].ItemArray);
}

Note that you need to clone the source DataSet in order to preserve its schema, which will enable the batch update process on the PocketPC device to work properly. You then loop through the source DataSet and copy each row to the target DataSet. This adds the "inserted" hint to the DiffGram for each row. You have to use the ItemArray property of each DataRow object, because a DataRow reference cannot be assigned to more than one DataTable (it generates an exception).

Sadly, the RowState property of the DataRow class is still read only in the .NET Framework v2.0. I'll request the change, though, and perhaps the Microsoft machine will respond favorably. Until next issue, stay angry and don't follow the rules that suck. My name is Jonathan Goodyear and I am the angryCoder.

Jonathan D Goodyear

&


Article Pages: < Previous - 1  2 

Page 1: Waiting to Inhale
Page 2: Secretary of RowState

How would you rate the quality of this article?
1 2 3 4 5
Poor      Outstanding

Tell us why you rated the content this way. (optional)

Average rating:
4 out of 5

11 people have rated this article.

Instantly Search Terabytes Of Text
“Lightning Fast”
– Redmond Mag
“Covers all data
sources” – eWeek
25+ fielded & full-text search options
dtSearch’s own document filters highlight hits in popular file types
Web Spider supports static & dynamic data
APIs for .NET, Java, C++, SQL, etc.
Win / Linux (64-bit & 32-bit)
www.dtSearch.com
 

      Sharepoint TechCon

 

Component One