473,692 Members | 2,197 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

dataset nulls

drg
I have a DataSet with a DateTime field. I am using an EventRow r, to update
it with values from a TextBox in a DataGrid. Suppose a DataGrid in edit mode
had a field with value: 7/7/2005. Then the user deletes this value. Now, I
want to update the DataSet (I know how to update the database) with a
statement like this: r.MyDate = null. However, I can't seem to find the
syntax to do this. Thanks!
Nov 17 '05 #1
8 2255
Strong-type your DataSet and the xsd generator will serialize a special method for setting nullable properties:

((DataRow) row).Set[column name]Null()

--
Dave Sexton
dave@www..jwaon line..com
-----------------------------------------------------------------------
"drg" <dr*@discussion s.microsoft.com > wrote in message news:6C******** *************** ***********@mic rosoft.com...
I have a DataSet with a DateTime field. I am using an EventRow r, to update
it with values from a TextBox in a DataGrid. Suppose a DataGrid in edit mode
had a field with value: 7/7/2005. Then the user deletes this value. Now, I
want to update the DataSet (I know how to update the database) with a
statement like this: r.MyDate = null. However, I can't seem to find the
syntax to do this. Thanks!

Nov 17 '05 #2
drg
I'm confused about how to get started with this. I have used VS to generate
the DataSet. If I look at the DataSet properties, it has a field that says
"AllowDBNul l" with the value "true" (however, it is grayed out). Then my code
attempts to: r.BTime = System.DBNull and the error says "class where variable
expected".

I have tried to modify the XSD file directly, as
http://www.adoguy.com/content.aspx?i...apter/Chapter5 suggests by
putting: codegen:nullVal ue="_empty" in XSD file, but then it doesn't validate
(doesn't like the codegen keyword) AND the DataSet disappears from the
component tray.

Also, when I preview the data in the DataSet, it shows the Null values, so
why won't it let me put them in myself. Thanks--Dave G

"Dave" wrote:
Strong-type your DataSet and the xsd generator will serialize a special method for setting nullable properties:

((DataRow) row).Set[column name]Null()

--
Dave Sexton
dave@www..jwaon line..com
-----------------------------------------------------------------------
"drg" <dr*@discussion s.microsoft.com > wrote in message news:6C******** *************** ***********@mic rosoft.com...
I have a DataSet with a DateTime field. I am using an EventRow r, to update
it with values from a TextBox in a DataGrid. Suppose a DataGrid in edit mode
had a field with value: 7/7/2005. Then the user deletes this value. Now, I
want to update the DataSet (I know how to update the database) with a
statement like this: r.MyDate = null. However, I can't seem to find the
syntax to do this. Thanks!


Nov 17 '05 #3
In message <4A************ *************** *******@microso ft.com>, drg
<dr*@discussion s.microsoft.com > writes
Then my code
attempts to: r.BTime = System.DBNull and the error says "class where variable
expected".


System.DBNull.V alue

HTH.

--
Steve Walker
Nov 17 '05 #4
drg
I have also tried: r.Btime = System.DBNull.V alue. The error I get is that it
can't convert it to System.DateTime .

"Steve Walker" wrote:
In message <4A************ *************** *******@microso ft.com>, drg
<dr*@discussion s.microsoft.com > writes
Then my code
attempts to: r.BTime = System.DBNull and the error says "class where variable
expected".


System.DBNull.V alue

HTH.

--
Steve Walker

Nov 17 '05 #5
In message <FE************ *************** *******@microso ft.com>, drg
<dr*@discussion s.microsoft.com > writes

"Steve Walker" wrote:
In message <4A************ *************** *******@microso ft.com>, drg
<dr*@discussion s.microsoft.com > writes
>Then my code
>attempts to: r.BTime = System.DBNull and the error says "class where
>variable
>expected".
System.DBNull.V alue

I have also tried: r.Btime = System.DBNull.V alue. The error I get is that it
can't convert it to System.DateTime .


That was the obvious answer. Beyond that I'm afraid I've got no idea. I
never do updates via datasets.

--
Steve Walker
Nov 17 '05 #6
If you have generated a strong-typed DataSet (i.e. used the designer to make a class that you can reference) then you can set your
property to null by calling this method:

r.SetBTimeNull( );

This will only work if you have a field named "BTime" (or by using codegen to rename the field to "BTime") and the field is
nullable. The easiest way to make a field nullable is to select the field in the .xsd designer, view the properties grid for that
field and set minOccurs to "0" (This means that the field may be sepecified 0 times, which is null).

I see that in a previous post you tried using codegen, so here's an explaination of why that didn't work for you:

"codegen" is an xml namespace that must be imported into your xml file to be used. It provides certain configuration capabilities
of the dataset generator such as changing the names of fields and methods on the class that will be created from your .xsd schema.

I threw together an example DataSet that shows some of the use of codgen (see the inline comments):

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="Dataset1" targetNamespace ="http://tempuri.org/Dataset1.xsd"
elementFormDefa ult="qualified" attributeFormDe fault="qualifie d"
xmlns="http://tempuri.org/Dataset1.xsd" xmlns:mstns="ht tp://tempuri.org/Dataset1.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="u rn:schemas-microsoft-com:xml-msdata"
xmlns:codegen=" urn:schemas-microsoft-com:xml-codegen"> <!-- THIS LINE IMPORTS THE codgen NAMESPACE -->
<xs:element name="Dataset1" msdata:IsDataSe t="true">
<xs:complexType >
<xs:choice maxOccurs="unbo unded">
<xs:element name="tbl_strin gs"
codegen:typedNa me="StringRow" <!-- This will name your element, in code, as "StringRow" -->
codgen:typedPlu ral="StringTabl e"> <!-- This will name your element collection, in code, as "StringTabl e" -->
<xs:complexType >
<xs:sequence>
<xs:element
codgen:typedNam e="StringFiel d" <!-- This will name your field, in code, as "StringFiel d" -->
name="vch_strin g_field" type="xs:string "
minOccurs="0" /> <!-- This will generate a "SetStringField Null" method -->
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>

When you compile this into a DataSet, you can do something like the following to see how codegen generated the names I specified
instead of the xml element names:

DataSet1 ds = new DataSet1();

StringTable table = DataSet1.String Table // "StringTabl e" instead of "Tables[0]"
table.AddString Row("test field value"); // "AddStringR ow" instead of the default "NewRow()" and code that goes with it

StringRow row = DataSet1.String Table[0]; // Directly query for the "StringRow" instance at the first index (zero index).

Console.WriteLi ne(row.StringFi eld); // "StringFiel d" as the name instead of "vch_string_fie ld"
// prints "test field value"

row.SetStringFi eldNull(); // What your looking for !!!!!
Console.WriteLi ne(row.StringFi eld);
// prints nothing

There are a few other options in codgen such as typedChildren and typedPlural which I use alot. They change the relational members
in code such as the parent property name of a child row, and the Get* method of the parent table for retrieving an array of
children.

Hope it helps :)

--
Dave Sexton
dave@www..jwaon line..com
-----------------------------------------------------------------------
"drg" <dr*@discussion s.microsoft.com > wrote in message news:4A******** *************** ***********@mic rosoft.com...
I'm confused about how to get started with this. I have used VS to generate
the DataSet. If I look at the DataSet properties, it has a field that says
"AllowDBNul l" with the value "true" (however, it is grayed out). Then my code
attempts to: r.BTime = System.DBNull and the error says "class where variable
expected".

I have tried to modify the XSD file directly, as
http://www.adoguy.com/content.aspx?i...apter/Chapter5 suggests by
putting: codegen:nullVal ue="_empty" in XSD file, but then it doesn't validate
(doesn't like the codegen keyword) AND the DataSet disappears from the
component tray.

Also, when I preview the data in the DataSet, it shows the Null values, so
why won't it let me put them in myself. Thanks--Dave G

"Dave" wrote:
Strong-type your DataSet and the xsd generator will serialize a special method for setting nullable properties:

((DataRow) row).Set[column name]Null()

--
Dave Sexton
dave@www..jwaon line..com
-----------------------------------------------------------------------
"drg" <dr*@discussion s.microsoft.com > wrote in message news:6C******** *************** ***********@mic rosoft.com...
>I have a DataSet with a DateTime field. I am using an EventRow r, to update
> it with values from a TextBox in a DataGrid. Suppose a DataGrid in edit mode
> had a field with value: 7/7/2005. Then the user deletes this value. Now, I
> want to update the DataSet (I know how to update the database) with a
> statement like this: r.MyDate = null. However, I can't seem to find the
> syntax to do this. Thanks!


Nov 17 '05 #7
drg
Dave, This is what I needed (and I had all along but didn't realize!):
r.SetBTimeNull( );


Thanks for your XML example, I think I'm getting the idea with strongly
typed DataSets. My problem is now solved, but I wanted to follow up on the
"modificati ons" you can make to the DataSet via the XSD file. In VS, I opened
the XML and added the codegen namespace and a "typedName" . The XML would
validate, but I don't believe it ever "regenerate d" the DataSet.cs file. In
other words, the "typed name" (r.BegTime) is still not available in my code,
just the default (r.BTime). Question, do you have to run the command line
program (forget the name) when you modify the XML with a codegen? Seems like
VS would do this for you, but I can't find where. Thanks!--Dave
Nov 17 '05 #8
VS will run it for u.

I must appologize, but I gave you the wrong xmlns -- sorry ;)

It should be:

xmlns:codegen=" urn:schemas-microsoft-com:xml-msprop"

(msprop, not codegen)

[...]
<xs:element codegen:typedNa me="BegTime"

--
Dave Sexton
dave@www..jwaon line..com
-----------------------------------------------------------------------
"drg" <dr*@discussion s.microsoft.com > wrote in message news:46******** *************** ***********@mic rosoft.com...
Dave, This is what I needed (and I had all along but didn't realize!):
r.SetBTimeNull( );


Thanks for your XML example, I think I'm getting the idea with strongly
typed DataSets. My problem is now solved, but I wanted to follow up on the
"modificati ons" you can make to the DataSet via the XSD file. In VS, I opened
the XML and added the codegen namespace and a "typedName" . The XML would
validate, but I don't believe it ever "regenerate d" the DataSet.cs file. In
other words, the "typed name" (r.BegTime) is still not available in my code,
just the default (r.BTime). Question, do you have to run the command line
program (forget the name) when you modify the XML with a codegen? Seems like
VS would do this for you, but I can't find where. Thanks!--Dave

Nov 17 '05 #9

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

Similar topics

1
3511
by: Efy. | last post by:
Hello, The following problam description I did not need to write, I just copied from the groups from others which met the error and allways the thread was 1 artical the problem was never resolved! So, please someone there , any idea? I've createed a typed dataset that I fill from a sql query. The problem comes when I try to access the elements after it's filled if I
5
7467
by: DraguVaso | last post by:
Hi, Something I don't understand about a Typed DataSet: When a value in the DataSet is DBNull, it throws this error: "Cannot get value because it is DBNull". But aren't Typed DataSets invented to make life easier, to be able to get to tge Tables and Values with less code, in less time? But with this thing you need to add a Try-Catch around every statement when using the value, add for each value a default value in your DataSet (and...
3
4589
by: Luther Miller | last post by:
I am using an XSLT file to convert data in a DataSet to XMLSS format for opening in Excel. Excel doesn't like the way Dates in the DataSet are being ouput. It appears that a timezone offset is being appended to the datetime; e.g., instead of "2003-08-26T00:00:00.0000000" I am getting "2003-08-26T00:00:00.0000000-07:00" in the output. If I could just get rid of the trailing "-07:00" in the output, I would be all set. I'm guessing this must...
0
1051
by: claire | last post by:
Hi, I am working on windows form project with a typed dataset. I have a form which has text boxes that are databound to the record in the dataset. when this form is being used to for a new record how do i bind the text boxes. Do i have to manually create a new record in the dataset first? if so what about the columns that dont allow nulls? Thank you in advance, i appreciate your time.
2
2626
by: a | last post by:
how to send an xml dataset to a Stored Procedure in mssql I have an xml file that I read into a dataset. and I'm trying to use a stored procedure (see SPROC #1 below) that inserts this xml dataset into an sql table via OpenXML. Nothing gets inserted into the sql table except nulls, so I think that perhaps I'm not actually sending the (xml) dataset to the SPROC. The code below fails on this line: sqlCommand1.ExecuteNonQuery();
0
1605
by: LunchBox | last post by:
I'm getting null values in a DataSet which is pulling its data from a web service. The nulls are creating 'System.Data.ConstraintException' in the fields that do not allow columns. I've tried finding the reason for the nulls, but I'm out of time. I need to erase the rows with nulls from the dataset. Here is what I have so far, and although it throws an Invalid Operation exception, it does delete the row with the null. But obviously...
1
2848
by: Matt Tinson | last post by:
Hello I have a datagrid with a datetimepicker column in it, which is bound to a dataset (MyDataset). The column in the dataset set that is mapped to the datetimepicker is called MyOrderDate and contains null values. I have tried to following to set the null values to 01/01/1900, as it doesn't accept nulls The above command appears after filling the dataset with the schema like s MySqlDataAdapter = New SqlDataAdapter(strquery, Mycon...
0
969
by: John Dalberg | last post by:
The code below (generated by the dataset designer) is receiving an exception because the 'searchfor' column has nulls but this column in SQL Server allows nulls. What am I missing? Shouldn't the generated code check for DBNull first?
19
19332
by: Dave | last post by:
If Iwant to check if dataset1.SelectQuery1.column1 == System.DBNull.Value. How do I do this? What I wrote above will give an error. -- L. A. Jones
0
8608
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
8540
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8963
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8806
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...
1
6459
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
5820
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4557
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2241
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1959
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.