473,569 Members | 2,590 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Table Adapter with null on numerical data

Hi,
Just get my hand on "Data Binding Windows Forms 2.0 Programming Smart
Client Data Applications with .Net", by Brian Noyes (Addison Wesley), with a
nice illustration on using generated code with strongly type dataset, in the
chapter 2.

BUT, I have a problem with Null, when on a not-string data. With String
Data, the Strong Type Data-Set generated code, by VS2005, allows to pass
Null as Empty string, but for non string data, the only option is to throw
an exception when a null is meet (inside the generated code).

Furthermore, it would have been nice if the framework would have allowed the
use of Nullable<T>, but it does not, quite UNFORTUNATELY. Indeed, a
"working" alternative is to modify, by hand, the generate code, changing the
int into int?, as example, and removing the throw new Exception, with return
(int?) null; and voila, just need to coalesce in my code:

row.GeneratedFi eld ?? default

or to check row.GeneratedFi eld.HasValue, but the problem with that
solution, is that your changes are destroyed each time the code is
regenerated. Not really good.

Handling with a try block also works, but doing so each time you access the
field:
try{ ... row.GeneratedFi eld; ... } catch { ... }
that just kill performance. Have to forget that solution.

Handling the conversion in the SQL Server, rather than in .Net code, is also
doable, but that increases the number of views on the server (to satisfy
particular needs of particular code implementation) , couple the code with
the view (without null), and add to the server burden, where the thick
client would have otherwise do the job very well... if it can handle the
null, that is.
Someone has some OTHER suggestion on how I can handle the null in the
strongly type code generated table adapters?

thanks,
Vanderghast, Access MVP
Apr 25 '06 #1
1 2071
Hi,
found (remembered) an alternative to coalesce ( ?? ), at least. Indeed,
instead of:
... row.GeneratedFi eld ?? defaultInThisCi rcumstance ... ; // pseudo
code

can 'simply' use:

... (row.IsGenerate dFieldNull ? defaultInThisCi rcumstance :
row.GeneratedFi eld) ...
without having the try{} block performance penalty, since IsXxxxNull is also
automatically generated, for each Xxxx field. And I don't have to build
special "view" either to convert my "nullable" fields as strings. It is not
"as elegant as" having a nullable data type, but can live with it, for sure.

Vanderghast, Access MVP

"Michel Walsh" <vanderghast@Vi rusAreFunnierTh anSpam> wrote in message
news:uS******** ******@TK2MSFTN GP02.phx.gbl...
Hi,
Just get my hand on "Data Binding Windows Forms 2.0 Programming Smart
Client Data Applications with .Net", by Brian Noyes (Addison Wesley), with
a nice illustration on using generated code with strongly type dataset, in
the chapter 2.

BUT, I have a problem with Null, when on a not-string data. With String
Data, the Strong Type Data-Set generated code, by VS2005, allows to pass
Null as Empty string, but for non string data, the only option is to throw
an exception when a null is meet (inside the generated code).

Furthermore, it would have been nice if the framework would have allowed
the use of Nullable<T>, but it does not, quite UNFORTUNATELY. Indeed, a
"working" alternative is to modify, by hand, the generate code, changing
the int into int?, as example, and removing the throw new Exception, with
return (int?) null; and voila, just need to coalesce in my code:

row.GeneratedFi eld ?? default

or to check row.GeneratedFi eld.HasValue, but the problem with that
solution, is that your changes are destroyed each time the code is
regenerated. Not really good.

Handling with a try block also works, but doing so each time you access
the field:
try{ ... row.GeneratedFi eld; ... } catch { ... }
that just kill performance. Have to forget that solution.

Handling the conversion in the SQL Server, rather than in .Net code, is
also doable, but that increases the number of views on the server (to
satisfy particular needs of particular code implementation) , couple the
code with the view (without null), and add to the server burden, where the
thick client would have otherwise do the job very well... if it can handle
the null, that is.
Someone has some OTHER suggestion on how I can handle the null in the
strongly type code generated table adapters?

thanks,
Vanderghast, Access MVP

Apr 27 '06 #2

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

Similar topics

1
4546
by: VMI | last post by:
How can I dump a datatable into an Access table (which contais exactly the same structure)? Somebody suggested doing this with a dataAdapter. I don't want to run an Insert query for each record (I assume that if the datatable and the Access table have the same structure, I can just dump it from one place to the other). I'd be dumping data to...
1
4463
by: JH | last post by:
I have a comma delimited file and I want to export it to an MS access table already designed with appropriate field names. How do I do this programmatically using VB.NET or C#? Thanks for any help in advance.
12
7548
by: VMI | last post by:
For some reason, the process of retrieving data (about 20 records) from an Access table that has 400K records to a dataTable is taking over 3 mins. to complete. Below is my code to connect to the DB and query the table. The table "audit" primary key is "Line". Another weird thing (but I guess that's another post) is that, while it's doing...
4
1781
by: Rich | last post by:
Hi, I keep getting an error when I try to insert a new record into a table (SQL 2000) that has a column that I've configured as 'Unique Null Allowed'. I used Visual Studio (2003) IDE SQL Data Adapter Wizard to create the stored procedures, data adapter, and dataset using a simple select statement with one paramater. Everything works fine...
7
2198
by: Jason Huang | last post by:
Hi, The SQL string is "select * from Customer where 0 > 1", and the DataSet should be null. Why MyDataSet.Tables.Count is 1, not 0? What kind of DataTable in this place? Thanks for help. Jason
1
2768
by: John | last post by:
Hi When using Table Adapter Configuration Wizard if 'Use SQL Statements' is selected as Command Type, the data table's name in dataset is retained and only its data adapter's select statements are replaced. If however 'Create new stored procedures' is selected as Command Type, the data table name in replaced by the name of the newly created...
5
1768
by: rdemyan via AccessMonster.com | last post by:
I have a table with about 80 fields. I'm using an import process to populate the table. It works fine, except for the following: Users generally don't specify values for a lot of numerical fields on the spreadsheet. I set the Access table up so that all the numerical values would have a default value of zero. I thought that when the...
12
19961
by: Randy | last post by:
Hi, Trying to pass along a table row delete to the datasource, but I'm crashing. Here is the code: Private Sub btnDeleteIngr_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDeleteIngr.Click Dim vbResponse As Integer vbResponse = MessageBox.Show("Are you sure that you want to delete " + tbIngr.Text + "?", "Confirm...
0
1463
by: Microsoft Newsserver | last post by:
Hi. I have a table adapter and one of the column s is a DateTime field. The underlying table allows for nulls and this is reflected in the properties for this column in the table adapter. However, I need to use an insert function and set the value to a null. I have tried using myTableAdaper.MyColumnName = DBNull.value; ( does not allow...
0
7924
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8130
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7677
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7979
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...
0
3653
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...
0
3643
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2115
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
1
1223
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
940
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...

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.