473,387 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Testing for DBNulls

I can't seem to find a test for DBNulls. Whatever I try doesn't work.

for (int x = 0; x < dataSet.Identity.Rows.Count; x++)
{
DataRow dataRow = dataSet.Tables["POI_Entity"].NewRow();

if (!dataSet.Identity[x].Chain_ID.Equals(DBNull.Value))
dataRow["Chain_Id"] = dataSet.Identity[x].Chain_ID;
else
dataRow["Chain_Id"] = 0;

dataSet.Tables["POI_Entity"].Rows.Add(dataRow);
}

I've also tried

(!Convert.IsDBNull(dataSet.Identity[x].Chain_ID)

That doesn't work either.

--
Regards,

Fred Chateau
http://hotelmotelnow.com
May 24 '07 #1
13 1729
Fred,

Have you set a point in the debugger and looked at what the value of:

dataSet.Identity[x].Chain_ID

Actually is?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Fred Chateau" <we*******@hotelmotelnow.comwrote in message
news:e3**************@TK2MSFTNGP04.phx.gbl...
>I can't seem to find a test for DBNulls. Whatever I try doesn't work.

for (int x = 0; x < dataSet.Identity.Rows.Count; x++)
{
DataRow dataRow = dataSet.Tables["POI_Entity"].NewRow();

if (!dataSet.Identity[x].Chain_ID.Equals(DBNull.Value))
dataRow["Chain_Id"] = dataSet.Identity[x].Chain_ID;
else
dataRow["Chain_Id"] = 0;

dataSet.Tables["POI_Entity"].Rows.Add(dataRow);
}

I've also tried

(!Convert.IsDBNull(dataSet.Identity[x].Chain_ID)

That doesn't work either.

--
Regards,

Fred Chateau
http://hotelmotelnow.com

May 24 '07 #2
try
if (dataSet.Identity[x].Chain_ID != null)
"Fred Chateau" <we*******@hotelmotelnow.comwrote in message
news:e3**************@TK2MSFTNGP04.phx.gbl...
>I can't seem to find a test for DBNulls. Whatever I try doesn't work.

for (int x = 0; x < dataSet.Identity.Rows.Count; x++)
{
DataRow dataRow = dataSet.Tables["POI_Entity"].NewRow();

if (!dataSet.Identity[x].Chain_ID.Equals(DBNull.Value))
dataRow["Chain_Id"] = dataSet.Identity[x].Chain_ID;
else
dataRow["Chain_Id"] = 0;

dataSet.Tables["POI_Entity"].Rows.Add(dataRow);
}

I've also tried

(!Convert.IsDBNull(dataSet.Identity[x].Chain_ID)

That doesn't work either.

--
Regards,

Fred Chateau
http://hotelmotelnow.com
May 24 '07 #3
Fred Chateau wrote:
I can't seem to find a test for DBNulls. Whatever I try doesn't work.

for (int x = 0; x < dataSet.Identity.Rows.Count; x++)
{
DataRow dataRow = dataSet.Tables["POI_Entity"].NewRow();

if (!dataSet.Identity[x].Chain_ID.Equals(DBNull.Value))
dataRow["Chain_Id"] = dataSet.Identity[x].Chain_ID;
else
dataRow["Chain_Id"] = 0;

dataSet.Tables["POI_Entity"].Rows.Add(dataRow);
}

I've also tried

(!Convert.IsDBNull(dataSet.Identity[x].Chain_ID)

That doesn't work either.
What kind of object does your variable "dataSet" reference?

If you have a DataRow, it has the method IsNull that you can use to
check for DbNull values.

If you have a data reader, it has the method IsDbNull that you can use
to check for DbNull values.

--
Göran Andersson
_____
http://www.guffa.com
May 24 '07 #4
Well, I can't believe I found it but I did. I had to edit the code generated
by XSD.

[System.Diagnostics.DebuggerNonUserCodeAttribute()]
public string Chain_ID {
get {
try {
if (!Convert.IsDBNull(this[this.tableIdentity.Chain_IDColumn])) <--
Added code
return ((string) (this[this.tableIdentity.Chain_IDColumn]));
else
return "0";
<-- Added code
}
catch (System.InvalidCastException e) {
throw new System.Data.StrongTypingException("The value for column
\'Chain_ID\' in table \'Identity\' is DBNull.", e);
}
}
set {
this[this.tableIdentity.Chain_IDColumn] = value;
}
}

--
Regards,

Fred Chateau
http://hotelmotelnow.com
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote in
message news:uh**************@TK2MSFTNGP04.phx.gbl...
Fred,

Have you set a point in the debugger and looked at what the value of:

dataSet.Identity[x].Chain_ID

Actually is?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Fred Chateau" <we*******@hotelmotelnow.comwrote in message
news:e3**************@TK2MSFTNGP04.phx.gbl...
>>I can't seem to find a test for DBNulls. Whatever I try doesn't work.

for (int x = 0; x < dataSet.Identity.Rows.Count; x++)
{
DataRow dataRow = dataSet.Tables["POI_Entity"].NewRow();

if (!dataSet.Identity[x].Chain_ID.Equals(DBNull.Value))
dataRow["Chain_Id"] = dataSet.Identity[x].Chain_ID;
else
dataRow["Chain_Id"] = 0;

dataSet.Tables["POI_Entity"].Rows.Add(dataRow);
}

I've also tried

(!Convert.IsDBNull(dataSet.Identity[x].Chain_ID)

That doesn't work either.

--
Regards,

Fred Chateau
http://hotelmotelnow.com


May 24 '07 #5
Fred,

Well, I wouldn't do that. What I was recommending was to determine what
the value that was being returned was through the debugger in your program,
and then using that knowledge to change the code.

Generally, I wouldn't change the designer code, because it will not
respect your changes if you make changes through the designer.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Fred Chateau" <we*******@hotelmotelnow.comwrote in message
news:uC**************@TK2MSFTNGP02.phx.gbl...
Well, I can't believe I found it but I did. I had to edit the code
generated by XSD.

[System.Diagnostics.DebuggerNonUserCodeAttribute()]
public string Chain_ID {
get {
try {
if (!Convert.IsDBNull(this[this.tableIdentity.Chain_IDColumn])) <--
Added code
return ((string) (this[this.tableIdentity.Chain_IDColumn]));
else
return "0"; <-- Added code
}
catch (System.InvalidCastException e) {
throw new System.Data.StrongTypingException("The value for column
\'Chain_ID\' in table \'Identity\' is DBNull.", e);
}
}
set {
this[this.tableIdentity.Chain_IDColumn] = value;
}
}

--
Regards,

Fred Chateau
http://hotelmotelnow.com
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote
in message news:uh**************@TK2MSFTNGP04.phx.gbl...
>Fred,

Have you set a point in the debugger and looked at what the value of:

dataSet.Identity[x].Chain_ID

Actually is?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Fred Chateau" <we*******@hotelmotelnow.comwrote in message
news:e3**************@TK2MSFTNGP04.phx.gbl...
>>>I can't seem to find a test for DBNulls. Whatever I try doesn't work.

for (int x = 0; x < dataSet.Identity.Rows.Count; x++)
{
DataRow dataRow = dataSet.Tables["POI_Entity"].NewRow();

if (!dataSet.Identity[x].Chain_ID.Equals(DBNull.Value))
dataRow["Chain_Id"] = dataSet.Identity[x].Chain_ID;
else
dataRow["Chain_Id"] = 0;

dataSet.Tables["POI_Entity"].Rows.Add(dataRow);
}

I've also tried

(!Convert.IsDBNull(dataSet.Identity[x].Chain_ID)

That doesn't work either.

--
Regards,

Fred Chateau
http://hotelmotelnow.com



May 24 '07 #6
I'm not sure how I could do anything else. It tries to cast the XML Node
value to a string and if the cast fails, it throws an Invalid Cast
Exception, then sends out the message: The value for column <columnNamein
table <tableNameis DBNull.

It should pass the DBNull along so I can test for it, but it never gets that
far. You can't modify your code when you don't even have access to the
variable.

Do you think there's a way to catch the exception? Even if there is, isn't
that bad practice to use an exception to determine a decision branch in the
code?

--
Regards,

Fred Chateau
http://hotelmotelnow.com
--
Regards,

Fred Chateau
http://hotelmotelnow.com

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote in
message news:e7**************@TK2MSFTNGP03.phx.gbl...
Fred,

Well, I wouldn't do that. What I was recommending was to determine
what the value that was being returned was through the debugger in your
program, and then using that knowledge to change the code.

Generally, I wouldn't change the designer code, because it will not
respect your changes if you make changes through the designer.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Fred Chateau" <we*******@hotelmotelnow.comwrote in message
news:uC**************@TK2MSFTNGP02.phx.gbl...
>Well, I can't believe I found it but I did. I had to edit the code
generated by XSD.

[System.Diagnostics.DebuggerNonUserCodeAttribute()]
public string Chain_ID {
get {
try {
if (!Convert.IsDBNull(this[this.tableIdentity.Chain_IDColumn])) <--
Added code
return ((string) (this[this.tableIdentity.Chain_IDColumn]));
else
return "0"; <-- Added code
}
catch (System.InvalidCastException e) {
throw new System.Data.StrongTypingException("The value for column
\'Chain_ID\' in table \'Identity\' is DBNull.", e);
}
}
set {
this[this.tableIdentity.Chain_IDColumn] = value;
}
}

--
Regards,

Fred Chateau
http://hotelmotelnow.com
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote
in message news:uh**************@TK2MSFTNGP04.phx.gbl...
>>Fred,

Have you set a point in the debugger and looked at what the value of:

dataSet.Identity[x].Chain_ID

Actually is?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Fred Chateau" <we*******@hotelmotelnow.comwrote in message
news:e3**************@TK2MSFTNGP04.phx.gbl...
I can't seem to find a test for DBNulls. Whatever I try doesn't work.

for (int x = 0; x < dataSet.Identity.Rows.Count; x++)
{
DataRow dataRow = dataSet.Tables["POI_Entity"].NewRow();

if (!dataSet.Identity[x].Chain_ID.Equals(DBNull.Value))
dataRow["Chain_Id"] = dataSet.Identity[x].Chain_ID;
else
dataRow["Chain_Id"] = 0;

dataSet.Tables["POI_Entity"].Rows.Add(dataRow);
}

I've also tried

(!Convert.IsDBNull(dataSet.Identity[x].Chain_ID)

That doesn't work either.

--
Regards,

Fred Chateau
http://hotelmotelnow.com



May 24 '07 #7
Fred,

This is a typed data set, right? You should be able to highlight the
column in the designer and indicate that you want it to return DBNull when
null is encountered for that column.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Fred Chateau" <we*******@hotelmotelnow.comwrote in message
news:u0**************@TK2MSFTNGP03.phx.gbl...
I'm not sure how I could do anything else. It tries to cast the XML Node
value to a string and if the cast fails, it throws an Invalid Cast
Exception, then sends out the message: The value for column <columnName>
in table <tableNameis DBNull.

It should pass the DBNull along so I can test for it, but it never gets
that far. You can't modify your code when you don't even have access to
the variable.

Do you think there's a way to catch the exception? Even if there is, isn't
that bad practice to use an exception to determine a decision branch in
the code?

--
Regards,

Fred Chateau
http://hotelmotelnow.com
--
Regards,

Fred Chateau
http://hotelmotelnow.com

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote
in message news:e7**************@TK2MSFTNGP03.phx.gbl...
>Fred,

Well, I wouldn't do that. What I was recommending was to determine
what the value that was being returned was through the debugger in your
program, and then using that knowledge to change the code.

Generally, I wouldn't change the designer code, because it will not
respect your changes if you make changes through the designer.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Fred Chateau" <we*******@hotelmotelnow.comwrote in message
news:uC**************@TK2MSFTNGP02.phx.gbl...
>>Well, I can't believe I found it but I did. I had to edit the code
generated by XSD.

[System.Diagnostics.DebuggerNonUserCodeAttribute()]
public string Chain_ID {
get {
try {
if (!Convert.IsDBNull(this[this.tableIdentity.Chain_IDColumn])) <--
Added code
return ((string) (this[this.tableIdentity.Chain_IDColumn]));
else
return "0"; <-- Added code
}
catch (System.InvalidCastException e) {
throw new System.Data.StrongTypingException("The value for column
\'Chain_ID\' in table \'Identity\' is DBNull.", e);
}
}
set {
this[this.tableIdentity.Chain_IDColumn] = value;
}
}

--
Regards,

Fred Chateau
http://hotelmotelnow.com
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote
in message news:uh**************@TK2MSFTNGP04.phx.gbl...
Fred,

Have you set a point in the debugger and looked at what the value
of:

dataSet.Identity[x].Chain_ID

Actually is?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Fred Chateau" <we*******@hotelmotelnow.comwrote in message
news:e3**************@TK2MSFTNGP04.phx.gbl...
>I can't seem to find a test for DBNulls. Whatever I try doesn't work.
>
for (int x = 0; x < dataSet.Identity.Rows.Count; x++)
{
DataRow dataRow = dataSet.Tables["POI_Entity"].NewRow();
>
if (!dataSet.Identity[x].Chain_ID.Equals(DBNull.Value))
dataRow["Chain_Id"] = dataSet.Identity[x].Chain_ID;
else
dataRow["Chain_Id"] = 0;
>
dataSet.Tables["POI_Entity"].Rows.Add(dataRow);
}
>
I've also tried
>
(!Convert.IsDBNull(dataSet.Identity[x].Chain_ID)
>
That doesn't work either.
>
--
Regards,
>
Fred Chateau
http://hotelmotelnow.com
>




May 24 '07 #8
for (int x = 0; x < dataSet.Identity.Rows.Count; x++)
{
DataRow dataRow = dataSet.Tables["POI_Entity"].NewRow();

if (!dataSet.Identity[x].Chain_ID.Equals(DBNull.Value))
dataRow["Chain_Id"] = dataSet.Identity[x].Chain_ID;
else
dataRow["Chain_Id"] = 0;

dataSet.Tables["POI_Entity"].Rows.Add(dataRow);
}

I've also tried

(!Convert.IsDBNull(dataSet.Identity[x].Chain_ID)

That doesn't work either.
foreach (IdentityRow identtyRow in dataSet.Identity)
{

if (identityRow.IsChain_IDNull)
{
}
else
{
}

dataSet.POI_Entity.New
}
May 24 '07 #9
Well, that worked too.

The choices are empty, null and throw exception. I set the value to return
an empty string and then tested for the empty string.

Thanks again, Nicholas.

--
Regards,

Fred Chateau
http://hotelmotelnow.com

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote in
message news:ee**************@TK2MSFTNGP02.phx.gbl...
Fred,

This is a typed data set, right? You should be able to highlight the
column in the designer and indicate that you want it to return DBNull when
null is encountered for that column.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Fred Chateau" <we*******@hotelmotelnow.comwrote in message
news:u0**************@TK2MSFTNGP03.phx.gbl...
>I'm not sure how I could do anything else. It tries to cast the XML Node
value to a string and if the cast fails, it throws an Invalid Cast
Exception, then sends out the message: The value for column <columnName>
in table <tableNameis DBNull.

It should pass the DBNull along so I can test for it, but it never gets
that far. You can't modify your code when you don't even have access to
the variable.

Do you think there's a way to catch the exception? Even if there is,
isn't that bad practice to use an exception to determine a decision
branch in the code?

--
Regards,

Fred Chateau
http://hotelmotelnow.com
--
Regards,

Fred Chateau
http://hotelmotelnow.com

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote
in message news:e7**************@TK2MSFTNGP03.phx.gbl...
>>Fred,

Well, I wouldn't do that. What I was recommending was to determine
what the value that was being returned was through the debugger in your
program, and then using that knowledge to change the code.

Generally, I wouldn't change the designer code, because it will not
respect your changes if you make changes through the designer.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Fred Chateau" <we*******@hotelmotelnow.comwrote in message
news:uC**************@TK2MSFTNGP02.phx.gbl...
Well, I can't believe I found it but I did. I had to edit the code
generated by XSD.

[System.Diagnostics.DebuggerNonUserCodeAttribute()]
public string Chain_ID {
get {
try {
if (!Convert.IsDBNull(this[this.tableIdentity.Chain_IDColumn])) <--
Added code
return ((string) (this[this.tableIdentity.Chain_IDColumn]));
else
return "0"; <-- Added code
}
catch (System.InvalidCastException e) {
throw new System.Data.StrongTypingException("The value for column
\'Chain_ID\' in table \'Identity\' is DBNull.", e);
}
}
set {
this[this.tableIdentity.Chain_IDColumn] = value;
}
}

--
Regards,

Fred Chateau
http://hotelmotelnow.com
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com>
wrote in message news:uh**************@TK2MSFTNGP04.phx.gbl...
Fred,
>
Have you set a point in the debugger and looked at what the value
of:
>
dataSet.Identity[x].Chain_ID
>
Actually is?
>
>
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
>
"Fred Chateau" <we*******@hotelmotelnow.comwrote in message
news:e3**************@TK2MSFTNGP04.phx.gbl.. .
>>I can't seem to find a test for DBNulls. Whatever I try doesn't work.
>>
>for (int x = 0; x < dataSet.Identity.Rows.Count; x++)
>{
> DataRow dataRow = dataSet.Tables["POI_Entity"].NewRow();
>>
> if (!dataSet.Identity[x].Chain_ID.Equals(DBNull.Value))
> dataRow["Chain_Id"] = dataSet.Identity[x].Chain_ID;
> else
> dataRow["Chain_Id"] = 0;
>>
>dataSet.Tables["POI_Entity"].Rows.Add(dataRow);
>}
>>
>I've also tried
>>
>(!Convert.IsDBNull(dataSet.Identity[x].Chain_ID)
>>
>That doesn't work either.
>>
>--
>Regards,
>>
>Fred Chateau
>http://hotelmotelnow.com
>>
>
>




May 24 '07 #10
Fred,

Just a note, in this case, I would opt to return null, since there is a
difference between null and an empty string in both .NET and DB-land.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Fred Chateau" <we*******@hotelmotelnow.comwrote in message
news:es**************@TK2MSFTNGP06.phx.gbl...
Well, that worked too.

The choices are empty, null and throw exception. I set the value to return
an empty string and then tested for the empty string.

Thanks again, Nicholas.

--
Regards,

Fred Chateau
http://hotelmotelnow.com

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote
in message news:ee**************@TK2MSFTNGP02.phx.gbl...
>Fred,

This is a typed data set, right? You should be able to highlight the
column in the designer and indicate that you want it to return DBNull
when null is encountered for that column.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Fred Chateau" <we*******@hotelmotelnow.comwrote in message
news:u0**************@TK2MSFTNGP03.phx.gbl...
>>I'm not sure how I could do anything else. It tries to cast the XML Node
value to a string and if the cast fails, it throws an Invalid Cast
Exception, then sends out the message: The value for column <columnName>
in table <tableNameis DBNull.

It should pass the DBNull along so I can test for it, but it never gets
that far. You can't modify your code when you don't even have access to
the variable.

Do you think there's a way to catch the exception? Even if there is,
isn't that bad practice to use an exception to determine a decision
branch in the code?

--
Regards,

Fred Chateau
http://hotelmotelnow.com
--
Regards,

Fred Chateau
http://hotelmotelnow.com

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote
in message news:e7**************@TK2MSFTNGP03.phx.gbl...
Fred,

Well, I wouldn't do that. What I was recommending was to determine
what the value that was being returned was through the debugger in your
program, and then using that knowledge to change the code.

Generally, I wouldn't change the designer code, because it will not
respect your changes if you make changes through the designer.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Fred Chateau" <we*******@hotelmotelnow.comwrote in message
news:uC**************@TK2MSFTNGP02.phx.gbl...
Well, I can't believe I found it but I did. I had to edit the code
generated by XSD.
>
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
public string Chain_ID {
get {
try {
if (!Convert.IsDBNull(this[this.tableIdentity.Chain_IDColumn]))
<-- Added code
return ((string) (this[this.tableIdentity.Chain_IDColumn]));
else
return "0"; <-- Added code
}
catch (System.InvalidCastException e) {
throw new System.Data.StrongTypingException("The value for column
\'Chain_ID\' in table \'Identity\' is DBNull.", e);
}
}
set {
this[this.tableIdentity.Chain_IDColumn] = value;
}
}
>
--
Regards,
>
Fred Chateau
http://hotelmotelnow.com
>
>
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com>
wrote in message news:uh**************@TK2MSFTNGP04.phx.gbl...
>Fred,
>>
> Have you set a point in the debugger and looked at what the value
>of:
>>
>dataSet.Identity[x].Chain_ID
>>
> Actually is?
>>
>>
>--
> - Nicholas Paldino [.NET/C# MVP]
> - mv*@spam.guard.caspershouse.com
>>
>"Fred Chateau" <we*******@hotelmotelnow.comwrote in message
>news:e3**************@TK2MSFTNGP04.phx.gbl. ..
>>>I can't seem to find a test for DBNulls. Whatever I try doesn't work.
>>>
>>for (int x = 0; x < dataSet.Identity.Rows.Count; x++)
>>{
>> DataRow dataRow = dataSet.Tables["POI_Entity"].NewRow();
>>>
>> if (!dataSet.Identity[x].Chain_ID.Equals(DBNull.Value))
>> dataRow["Chain_Id"] = dataSet.Identity[x].Chain_ID;
>> else
>> dataRow["Chain_Id"] = 0;
>>>
>>dataSet.Tables["POI_Entity"].Rows.Add(dataRow);
>>}
>>>
>>I've also tried
>>>
>>(!Convert.IsDBNull(dataSet.Identity[x].Chain_ID)
>>>
>>That doesn't work either.
>>>
>>--
>>Regards,
>>>
>>Fred Chateau
>>http://hotelmotelnow.com
>>>
>>
>>
>
>



May 24 '07 #11
Well, that worked too.
>
The choices are empty, null and throw exception. I set the value to return
an empty string and then tested for the empty string.
Sorry, I sent my last email off prematurely (on another thread). For
strongly-typed datasets life is much easier. Take a look at the
"whatever.Designer.cs" file under your ".xsd" file. Here's a quickly-written
analogue of your original post. It's what you should be doing but it might
be a little rough since I don't have your actual file to work with (and I'm
doing this from memory).

foreach (IdentityRow identyRow in dataSet.Identity)
{
POI_EntityRow newRow = dataSet.POI_Entity.NewPOI_EntityRow();

if (!identityRow.IsChain_IDNull)
{
newRow.Chain_Id = idenityRow.Chain_ID;
}
else
{
newRow.Chain_Id = 0;
}

dataSet.POI_Entity.AddPOI_EntityRow(newRow);
}
May 24 '07 #12
Larry, I set the designer back to "Throw Exception" and used your method of
testing for DBNulls. It works well, and like Nicholas said, it's better to
handle the problem in your own code than changing code in designers, or even
designer settings.

I think this is the way DBNull was meant to be used, that is, testing for it
like you would test for object nulls and responding in an appropriate
manner.

--
Regards,

Fred Chateau
http://hotelmotelnow.com
"Larry Smith" <no_spam@_nospam.comwrote in message
news:u0**************@TK2MSFTNGP06.phx.gbl...
>Well, that worked too.

The choices are empty, null and throw exception. I set the value to
return an empty string and then tested for the empty string.

Sorry, I sent my last email off prematurely (on another thread). For
strongly-typed datasets life is much easier. Take a look at the
"whatever.Designer.cs" file under your ".xsd" file. Here's a
quickly-written analogue of your original post. It's what you should be
doing but it might be a little rough since I don't have your actual file
to work with (and I'm doing this from memory).

foreach (IdentityRow identyRow in dataSet.Identity)
{
POI_EntityRow newRow = dataSet.POI_Entity.NewPOI_EntityRow();

if (!identityRow.IsChain_IDNull)
{
newRow.Chain_Id = idenityRow.Chain_ID;
}
else
{
newRow.Chain_Id = 0;
}

dataSet.POI_Entity.AddPOI_EntityRow(newRow);
}

May 25 '07 #13
Larry, I set the designer back to "Throw Exception" and used your method
of testing for DBNulls. It works well, and like Nicholas said, it's better
to handle the problem in your own code than changing code in designers, or
even designer settings.

I think this is the way DBNull was meant to be used, that is, testing for
it like you would test for object nulls and responding in an appropriate
manner.
Yes, but also note how much easier it is to work in general using
strongly-typed datasets. There's a class for each table and a corresponding
row class where each field (column) is exposed as a property IOW, you no
longer have to work with a "DataTable" or "DataRow" directly anymore (most
of the time anyway). Other properties/functions in "whatever.Designer.cs"
greatly simplify the entire "DataSet" experience. You can also easily extend
each table and row class by redeclaring it in "whatever.cs" using the
"partial" keyword (for VS2005). This allows you to add your own custom
functions which is the way I handle things. Good luck.
May 25 '07 #14

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

Similar topics

4
by: Hugh Cowan | last post by:
Hello, I don't program full-time (anymore), but I do try and stay on-top of the latest technologies and like most are always trying to upgrade my skills and remain current (as much as is...
0
by: Jonathan Allen | last post by:
We have found that our method of testing does not match traditional text-book methodologies. I decided to write a short white paper on it so that I could get your opinions. Does anyone else use...
0
by: Brian Russell | last post by:
We have three servers (beyond my development box) in our organization. The first is a testing server that has IIS and SQL Server on it. The second is another testing server that also has IIS and...
72
by: Jacob | last post by:
I have compiled a set og unit testing recommendations based on my own experience on the concept. Feedback and suggestions for improvements are appreciated: ...
58
by: nw | last post by:
Hi, I have been asked to teach a short course on testing in C++. Until now I have used my own testing classes (which from what I've seen seem similar to the boost unit testing classes)....
18
by: Andrew Wan | last post by:
I have been developing web applications with ASP & Javascript for a long time. I have been using Visual Studio 2003.NET. While VS2003 is okay for intellisense of ASP & Javascript, it's still not...
0
by: Matthew Fitzgibbons | last post by:
I'm by no means a testing expert, but I'll take a crack at it. Casey McGinty wrote: I've never run into this. Rule of thumb: always separate software from hardware. Write mock classes or...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
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...

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.