Solved

How to programatically create a DataRowView in ADO.NET

Posted on 2009-07-13
4
1,034 Views
Last Modified: 2013-11-08
My problem is when I want to create a new row in a typed DataTable and edit it using DataBound WPF controls. Using the (typed) DataTable method: NewTABLERow() I can get a new instance of a typed datarow for TABLE. The particular database table I'm refering to has several columns that allow Null values.
When I bind, for example, a textbox to a Propery from the (Typed) DataRow that contains a Null value, an exception is thrown (StrongTypingException).

Instead of using the typed DataRow, if I used instead a DataRowView of the typed DataRow I should be ok, because no exception would be thrown... The problem is that I'm not finding a way of creating the DataRowView out of the typed DataRow...

Thanks in advance,
Rui
0
Comment
Question by:rui_dias
[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
  • 2
  • 2
4 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 50 total points
ID: 24849714
If you are working with String data in the typed DataSet designer, you can change the field to not throw an exception for null data.


Typed-DataSet-Designer----Null-S.png
0
 

Author Comment

by:rui_dias
ID: 24859289
That does work, thank you.

The way I ended up doing it was, using a view of the DataTable I wanted to add a DataRow to, I used the DataRowView that is returned when you add a new row to the DataView.
MyDataSet.MyDataTable dataTable = new MyDataSet.MyDataTable();
 
//Fill the data table...
 
DataView dataView = dataTable.DefaultView;
 
//To get the new DataRowView:
DataRowView dataRowView = dataView.AddNew();
dataRowView.BeginEdit();
 
//edit the dataRowView here...
 
//Accept(EndEdit) or reject(CancelEdit) the changes: if rejected 
//the DataRowView is not added to the DataTable!
 
dataRowView.EndEdit();
 
//or: dataRowView.CancelEdit();

Open in new window

0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 24859439
I usually don't go down that route of adding to the DataView with typed DataSets, since you can add to the underlying DataTable, and the changes would be reflected in the DataView.
0
 

Author Comment

by:rui_dias
ID: 24861706
That is true, but the problem is, when you create the typed dataset using the designer from a database with lots of fields that allow null, you get that "Throw Exception" behavior by default on all of them...

I was just trying to find a solution that didn't involve changing the "throw exception" behavior on all of them "by hand", in the designer. Using the views apparently works fine and has the added advantage of not being necessary to do anything to the dataset that is automatically generated using the designer.
0

Featured Post

Turn Insights Into Action

You’ve already invested in ITSM tools, chat applications, automation utilities, and more. Fortify these solutions with intelligent communications so you can drive business processes forward.

With xMatters, you'll never miss a beat.

Question has a verified solution.

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

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

695 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