473,386 Members | 1,720 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,386 software developers and data experts.

Why doesn't IsDBNull detect DBNull?

jim
This line of code returns error 13, cast from 'DBNull' to type 'String' is not valid

If IsDBNull(Clinics.Clinics.Item(A).Workphone) The

<other code
End I

Clinics.Clinics is a dataset that was loaded using a left join from two MS SQL database tables. The workphone element is null because there was no corresponding record from the right side of the join

The generated code for retrieving the value of 'Workphone' as a dataset property is detecting the DBNull and giving the cast error before the VB application code line can do its check

I have to be missing something - having a function 'IsDBNull' that is not able to check for a DBNull is inconsisten

Ji
Jul 21 '05 #1
19 3561


Anyway, I don't think it's the IsDbNull causing your problem and it can
definitely check for null values. I think the problem is in your Property.
I'd need to see the accessor b/c it won't let you explicitly set a string
value to DbNull, but depending on the property it could end up trying to do
just that resulting in the cast exception. Looking at the usage too and
that exception, all you are doing is an evaluation so the conversion is
being done inside the parens. As such, it's much more likely that it's
causing the exception rather than the use of IsDbNull.

can you first this statement without an exception
MessageBox.Show(Clinics.Clinics.Item(A).WorkPhone) 'Assuming workphone is a
string?

Anyway, it'd help if I could see the accessor, but I'm 99% sure this is the
problem...whatever is being used to set a property of type string is DbNull
and that won't work.

I use IsDbNull all the time to check for fields that are Varchar in the DB,
hence map to System.String for the datacolumn type and have never had a
problem. I really think it's the accessor. If the messagebox command
throws an exception , then we've pretty much ruled out the IsDbNull as the
cause.

"jim" <an*******@discussions.microsoft.com> wrote in message
news:87**********************************@microsof t.com...
This line of code returns error 13, cast from 'DBNull' to type 'String' is not valid.
If IsDBNull(Clinics.Clinics.Item(A).Workphone) Then

<other code>
End If
Clinics.Clinics is a dataset that was loaded using a left join from two MS SQL database tables. The workphone element is null because there was no
corresponding record from the right side of the join.
The generated code for retrieving the value of 'Workphone' as a dataset property is detecting the DBNull and giving the cast error before the VB
application code line can do its check.
I have to be missing something - having a function 'IsDBNull' that is not able to check for a DBNull is inconsistent
Jim

Jul 21 '05 #2


Anyway, I don't think it's the IsDbNull causing your problem and it can
definitely check for null values. I think the problem is in your Property.
I'd need to see the accessor b/c it won't let you explicitly set a string
value to DbNull, but depending on the property it could end up trying to do
just that resulting in the cast exception. Looking at the usage too and
that exception, all you are doing is an evaluation so the conversion is
being done inside the parens. As such, it's much more likely that it's
causing the exception rather than the use of IsDbNull.

can you first this statement without an exception
MessageBox.Show(Clinics.Clinics.Item(A).WorkPhone) 'Assuming workphone is a
string?

Anyway, it'd help if I could see the accessor, but I'm 99% sure this is the
problem...whatever is being used to set a property of type string is DbNull
and that won't work.

I use IsDbNull all the time to check for fields that are Varchar in the DB,
hence map to System.String for the datacolumn type and have never had a
problem. I really think it's the accessor. If the messagebox command
throws an exception , then we've pretty much ruled out the IsDbNull as the
cause.

"jim" <an*******@discussions.microsoft.com> wrote in message
news:87**********************************@microsof t.com...
This line of code returns error 13, cast from 'DBNull' to type 'String' is not valid.
If IsDBNull(Clinics.Clinics.Item(A).Workphone) Then

<other code>
End If
Clinics.Clinics is a dataset that was loaded using a left join from two MS SQL database tables. The workphone element is null because there was no
corresponding record from the right side of the join.
The generated code for retrieving the value of 'Workphone' as a dataset property is detecting the DBNull and giving the cast error before the VB
application code line can do its check.
I have to be missing something - having a function 'IsDBNull' that is not able to check for a DBNull is inconsistent
Jim

Jul 21 '05 #3
Jim
William

Thank you for the reply

I tried the message box and got the same error. WorkPhone is a string.

What specifically do you mean by the 'accessor'? Are you referring to the SQL statement that retrieves the data or the xml code for the dataset or the MS generated .vb code that gets the values as properties from the dataset or something else that I do not know about? I am including below the xml, the sql statement for the fill, and a snippet from the code that retrieves the data from the dataset. The error 13 is generated furhter down in the code in the same subroutine that does the fill

We may have a very basic misunderstanding of the proper usage of the development environment to define datasets

We use an SQLDataAdapter and reconfigure the GenAdapter selectcommand.commandtext depending on the data we are retrieving. The dataset has been defined by setting the adapter's select command, then generating the dataset. At execution time we do a fill of the appropriate dataset. Here is a copy of the xml from one of the datasets that we are having trouble with

<?xml version="1.0" standalone="yes" ?><xs:schema id="Clinics" targetNamespace="http://www.tempuri.org/Clinics.xsd" xmlns:mstns="http://www.tempuri.org/Clinics.xsd
xmlns="http://www.tempuri.org/Clinics.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" attributeFormDefault="qualified" elementFormDefault="qualified"><xs:element name="Clinics" msdata:IsDataSet="true"><xs:complexType><xs:choice maxOccurs="unbounded"><xs:element name="Clinics"><xs:complexType><xs:sequence><xs:el ement name="ClinicNum" type="xs:short" /><xs:element name="ClinicID" type="xs:string" /><xs:element name="ShortName" type="xs:string" /><xs:element name="LongName" type="xs:string" /><xs:element name="Root" type="xs:short" /><xs:element name="Group" type="xs:string" /><xs:element name="Discount" type="xs:string" /><xs:element name="License" type="xs:string" /><xs:element name="Doctor" type="xs:string" /><xs:element name="DirectorName" type="xs:string" /><xs:element name="DirectorTitle" type="xs:string" /><xs:element name="webURL" type="xs:string" /><xs:element name="AltContact" type="xs:string" /><xs:element name="AltContactTitle" type="xs:string" /><xs:element name="Billing" type="xs:string" /><xs:element name="Expr1" type="xs:string" /><xs:element name="Expr2" type="xs:dateTime" /><xs:element name="Expr3" type="xs:short" /><xs:element name="Expr4" msdata:ReadOnly="true" msdata:AutoIncrement="true" type="xs:int" /><xs:element name="Expr5" type="xs:int" /><xs:element name="BtBID" type="xs:int" /><xs:element name="branch" type="xs:string" /><xs:element name="addresstype" type="xs:string" /><xs:element name="addressline1" type="xs:string" /><xs:element name="streetnum" type="xs:string" /><xs:element name="Streetname" type="xs:string" /><xs:element name="Apt" type="xs:string" /><xs:element name="City" type="xs:string" /><xs:element name="State" type="xs:string" /><xs:element name="Postalcode" type="xs:string" /><xs:element name="Latitude" type="xs:string" /><xs:element name="Longitude" type="xs:string" /><xs:element name="County" type="xs:string" /><xs:element name="Homephone" type="xs:string" /><xs:element name="Workphone" type="xs:string" /><xs:element name="FAX" type="xs:string" /><xs:element name="Pager" type="xs:string" /><xs:element name="email" type="xs:string" /><xs:element name="altphone" type="xs:string" /><xs:element name="AltFAX" type="xs:string" /><xs:element name="AltPager" type="xs:string" /><xs:element name="altemail" type="xs:string" /><xs:element name="Startdate" type="xs:dateTime" /><xs:element name="Enddate" type="xs:dateTime" /><xs:element name="Entrydate" type="xs:dateTime" /><xs:element name="EnteredBy" type="xs:short" /></xs:sequence></xs:complexType></xs:element></xs:choice></xs:complexType><xs:unique name="Constraint1" msdata:PrimaryKey="true"><xs:selector xpath=".//mstns:Clinics" /><xs:field xpath="mstns:Expr5" /><xs:field xpath="mstns:addresstype" /></xs:unique></xs:element></xs:schema

And here is the code that retrieves the data from the dataset This is a snippet from Clinics.v

Public Property Workphone As String
Get
Return CType(Me(Me.tableClinics.WorkphoneColumn),String)
End Get
Set
Me(Me.tableClinics.WorkphoneColumn) = value
End Set
End Property

Finally, here is the sql string and subsequent code used to fill the dataset.

SQLString = "SELECT * FROM clinics "
SQLString = SQLString + " left Join Address on Address.BtBiD=Clinics.BtbID"
SQLString = SQLString + " And AddressType=" + Chr(39) + "CLN" + Chr(39)
SQLString = SQLString + " where Clinics.Branch = " + Chr(39) + Branch + Chr(39)
SQLString = SQLString + " order by shortname"

GenAdapter.SelectCommand.CommandText = SQLString
Clinics.Clinics.Clear()

Try
GenAdapter.Fill(Clinics.Clinics)
Catch e1 As Exception
MsgBox("Error filling ClinicsDataSet" + Chr(10) + e1.Message, MsgBoxStyle.OKOnly)
End Try

Jul 21 '05 #4
Jim
William

Thank you for the reply

I tried the message box and got the same error. WorkPhone is a string.

What specifically do you mean by the 'accessor'? Are you referring to the SQL statement that retrieves the data or the xml code for the dataset or the MS generated .vb code that gets the values as properties from the dataset or something else that I do not know about? I am including below the xml, the sql statement for the fill, and a snippet from the code that retrieves the data from the dataset. The error 13 is generated furhter down in the code in the same subroutine that does the fill

We may have a very basic misunderstanding of the proper usage of the development environment to define datasets

We use an SQLDataAdapter and reconfigure the GenAdapter selectcommand.commandtext depending on the data we are retrieving. The dataset has been defined by setting the adapter's select command, then generating the dataset. At execution time we do a fill of the appropriate dataset. Here is a copy of the xml from one of the datasets that we are having trouble with

<?xml version="1.0" standalone="yes" ?><xs:schema id="Clinics" targetNamespace="http://www.tempuri.org/Clinics.xsd" xmlns:mstns="http://www.tempuri.org/Clinics.xsd
xmlns="http://www.tempuri.org/Clinics.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" attributeFormDefault="qualified" elementFormDefault="qualified"><xs:element name="Clinics" msdata:IsDataSet="true"><xs:complexType><xs:choice maxOccurs="unbounded"><xs:element name="Clinics"><xs:complexType><xs:sequence><xs:el ement name="ClinicNum" type="xs:short" /><xs:element name="ClinicID" type="xs:string" /><xs:element name="ShortName" type="xs:string" /><xs:element name="LongName" type="xs:string" /><xs:element name="Root" type="xs:short" /><xs:element name="Group" type="xs:string" /><xs:element name="Discount" type="xs:string" /><xs:element name="License" type="xs:string" /><xs:element name="Doctor" type="xs:string" /><xs:element name="DirectorName" type="xs:string" /><xs:element name="DirectorTitle" type="xs:string" /><xs:element name="webURL" type="xs:string" /><xs:element name="AltContact" type="xs:string" /><xs:element name="AltContactTitle" type="xs:string" /><xs:element name="Billing" type="xs:string" /><xs:element name="Expr1" type="xs:string" /><xs:element name="Expr2" type="xs:dateTime" /><xs:element name="Expr3" type="xs:short" /><xs:element name="Expr4" msdata:ReadOnly="true" msdata:AutoIncrement="true" type="xs:int" /><xs:element name="Expr5" type="xs:int" /><xs:element name="BtBID" type="xs:int" /><xs:element name="branch" type="xs:string" /><xs:element name="addresstype" type="xs:string" /><xs:element name="addressline1" type="xs:string" /><xs:element name="streetnum" type="xs:string" /><xs:element name="Streetname" type="xs:string" /><xs:element name="Apt" type="xs:string" /><xs:element name="City" type="xs:string" /><xs:element name="State" type="xs:string" /><xs:element name="Postalcode" type="xs:string" /><xs:element name="Latitude" type="xs:string" /><xs:element name="Longitude" type="xs:string" /><xs:element name="County" type="xs:string" /><xs:element name="Homephone" type="xs:string" /><xs:element name="Workphone" type="xs:string" /><xs:element name="FAX" type="xs:string" /><xs:element name="Pager" type="xs:string" /><xs:element name="email" type="xs:string" /><xs:element name="altphone" type="xs:string" /><xs:element name="AltFAX" type="xs:string" /><xs:element name="AltPager" type="xs:string" /><xs:element name="altemail" type="xs:string" /><xs:element name="Startdate" type="xs:dateTime" /><xs:element name="Enddate" type="xs:dateTime" /><xs:element name="Entrydate" type="xs:dateTime" /><xs:element name="EnteredBy" type="xs:short" /></xs:sequence></xs:complexType></xs:element></xs:choice></xs:complexType><xs:unique name="Constraint1" msdata:PrimaryKey="true"><xs:selector xpath=".//mstns:Clinics" /><xs:field xpath="mstns:Expr5" /><xs:field xpath="mstns:addresstype" /></xs:unique></xs:element></xs:schema

And here is the code that retrieves the data from the dataset This is a snippet from Clinics.v

Public Property Workphone As String
Get
Return CType(Me(Me.tableClinics.WorkphoneColumn),String)
End Get
Set
Me(Me.tableClinics.WorkphoneColumn) = value
End Set
End Property

Finally, here is the sql string and subsequent code used to fill the dataset.

SQLString = "SELECT * FROM clinics "
SQLString = SQLString + " left Join Address on Address.BtBiD=Clinics.BtbID"
SQLString = SQLString + " And AddressType=" + Chr(39) + "CLN" + Chr(39)
SQLString = SQLString + " where Clinics.Branch = " + Chr(39) + Branch + Chr(39)
SQLString = SQLString + " order by shortname"

GenAdapter.SelectCommand.CommandText = SQLString
Clinics.Clinics.Clear()

Try
GenAdapter.Fill(Clinics.Clinics)
Catch e1 As Exception
MsgBox("Error filling ClinicsDataSet" + Chr(10) + e1.Message, MsgBoxStyle.OKOnly)
End Try

Jul 21 '05 #5
Hi Jim,
Return CType(Me(Me.tableClinics.WorkphoneColumn),String)


A column gives mostly information about the column and not the Item.

I think you want somehting as
\\\
dim my Rownumber as integer = 0
Return me.tableClincs(myRownumber).Workphone
///
However maybe I am wrong?
Cor
Jul 21 '05 #6
Hi Jim,
Return CType(Me(Me.tableClinics.WorkphoneColumn),String)


A column gives mostly information about the column and not the Item.

I think you want somehting as
\\\
dim my Rownumber as integer = 0
Return me.tableClincs(myRownumber).Workphone
///
However maybe I am wrong?
Cor
Jul 21 '05 #7
Jim
Hi Cor

This code is regenerated by MS every time there is a change to a dataset. It would be a huge pain to have to make this kind of a change to this code for every field in the dataset every time the dataset is modified

Ji

Jul 21 '05 #8
Jim
Hi Cor

This code is regenerated by MS every time there is a change to a dataset. It would be a huge pain to have to make this kind of a change to this code for every field in the dataset every time the dataset is modified

Ji

Jul 21 '05 #9
Hi Jim,

A dataset is mostly binded using a datasource or with mostly simple controls
direct to a property.

A dataset is basicly this
dataset.tables(x).rows(x).item(x)

What will say that a dataset contains tables which contains rows which
contains items, better said a dataset has references to tables, which have
references to rows, which has references to items.

When you do a dataadapter fill, that means that you fill a datatable (not a
dataset however it can be a table in a dataset).

So when you do not bind it, you will have to tell in my opinion wich row it
is in the datatable when you want a particulary item in a dataset. (And for
that you can use a lot of things by instance the bindingmanager.position)

A little bit confusing I did find it also when I started with the dataset is
that there is talked as well about columns, however a column describes the
type of the items.

I hope this helps?

Cor
Jul 21 '05 #10
Hi Jim,

A dataset is mostly binded using a datasource or with mostly simple controls
direct to a property.

A dataset is basicly this
dataset.tables(x).rows(x).item(x)

What will say that a dataset contains tables which contains rows which
contains items, better said a dataset has references to tables, which have
references to rows, which has references to items.

When you do a dataadapter fill, that means that you fill a datatable (not a
dataset however it can be a table in a dataset).

So when you do not bind it, you will have to tell in my opinion wich row it
is in the datatable when you want a particulary item in a dataset. (And for
that you can use a lot of things by instance the bindingmanager.position)

A little bit confusing I did find it also when I started with the dataset is
that there is talked as well about columns, however a column describes the
type of the items.

I hope this helps?

Cor
Jul 21 '05 #11
Your Get/Set statement is what I"m referring to. If the value it's
'getting' from the dataset returns DbNull, and you try returning it, it'll
blow up because the property is of Type String and it can't be converted.
Instead, you might want to do the IsDbNull check inside the Get statement
and if it is DbNull, return sting.Empty for instance.
"Jim" <an*******@discussions.microsoft.com> wrote in message
news:E8**********************************@microsof t.com...
William,

Thank you for the reply.

I tried the message box and got the same error. WorkPhone is a string.

What specifically do you mean by the 'accessor'? Are you referring to the SQL statement that retrieves the data or the xml code for the dataset or the
MS generated .vb code that gets the values as properties from the dataset or
something else that I do not know about? I am including below the xml, the
sql statement for the fill, and a snippet from the code that retrieves the
data from the dataset. The error 13 is generated furhter down in the code
in the same subroutine that does the fill.
We may have a very basic misunderstanding of the proper usage of the development environment to define datasets.
We use an SQLDataAdapter and reconfigure the GenAdapter selectcommand.commandtext depending on the data we are retrieving. The
dataset has been defined by setting the adapter's select command, then
generating the dataset. At execution time we do a fill of the appropriate
dataset. Here is a copy of the xml from one of the datasets that we are
having trouble with.

<?xml version="1.0" standalone="yes" ?><xs:schema id="Clinics" targetNamespace="http://www.tempuri.org/Clinics.xsd"
xmlns:mstns="http://www.tempuri.org/Clinics.xsd" xmlns="http://www.tempuri.org/Clinics.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" attributeFormDefault="qualified" elementFormDefault="qualified"><xs:element
name="Clinics" msdata:IsDataSet="true"><xs:complexType><xs:choice
maxOccurs="unbounded"><xs:element
name="Clinics"><xs:complexType><xs:sequence><xs:el ement name="ClinicNum"
type="xs:short" /><xs:element name="ClinicID" type="xs:string" /><xs:element
name="ShortName" type="xs:string" /><xs:element name="LongName"
type="xs:string" /><xs:element name="Root" type="xs:short" /><xs:element
name="Group" type="xs:string" /><xs:element name="Discount" type="xs:string"
/><xs:element name="License" type="xs:string" /><xs:element name="Doctor"
type="xs:string" /><xs:element name="DirectorName" type="xs:string"
/><xs:element name="DirectorTitle" type="xs:string" /><xs:element
name="webURL" type="xs:string" /><xs:element name="AltContact"
type="xs:string" /><xs:element name="AltContactTitle" type="xs:string"
/><xs:element name="Billing" type="xs:string" /><xs:element name="Expr1"
type="xs:string" /><xs:element name="Expr2" type="xs:dateTime" /><xs:element
name="Expr3" type="xs:short" /><xs:element name="Expr4"
msdata:ReadOnly="true" msdata:AutoIncrement="true" type="xs:int"
/><xs:element name="Expr5" type="xs:int" /><xs:element name="BtBID"
type="xs:int" /><xs:element name="branch" type="xs:string" /><xs:element
name="addresstype" type="xs:string" /><xs:element name="addressline1"
type="xs:string" /><xs:element name="streetnum" type="xs:string"
/><xs:element name="Streetname" type="xs:string" /><xs:element name="Apt"
type="xs:string" /><xs:element name="City" type="xs:string" /><xs:element
name="State" type="xs:string" /><xs:element name="Postalcode"
type="xs:string" /><xs:element name="Latitude" type="xs:string"
/><xs:element name="Longitude" type="xs:string" /><xs:element name="County"
type="xs:string" /><xs:element name="Homephone" type="xs:string"
/><xs:element name="Workphone" type="xs:string" /><xs:element name="FAX"
type="xs:string" /><xs:element name="Pager" type="xs:string" /><xs:element
name="email" type="xs:string" /><xs:element name="altphone" type="xs:string"
/><xs:element name="AltFAX" type="xs:string" /><xs:element name="AltPager"
type="xs:string" /><xs:element name="altemail" type="xs:string"
/><xs:element name="Startdate" type="xs:dateTime" /><xs:element
name="Enddate" type="xs:dateTime" /><xs:element name="Entrydate"
type="xs:dateTime" /><xs:element name="EnteredBy" type="xs:short"
/></xs:sequence></xs:complexType></xs:element></xs:choice></xs:complexType><
xs:unique name="Constraint1" msdata:PrimaryKey="true"><xs:selector
xpath=".//mstns:Clinics" /><xs:field xpath="mstns:Expr5" /><xs:field
xpath="mstns:addresstype" /></xs:unique></xs:element></xs:schema>

And here is the code that retrieves the data from the dataset This is a snippet from Clinics.vb
Public Property Workphone As String
Get
Return CType(Me(Me.tableClinics.WorkphoneColumn),String)
End Get
Set
Me(Me.tableClinics.WorkphoneColumn) = value
End Set
End Property

Finally, here is the sql string and subsequent code used to fill the dataset.
SQLString = "SELECT * FROM clinics "
SQLString = SQLString + " left Join Address on Address.BtBiD=Clinics.BtbID" SQLString = SQLString + " And AddressType=" + Chr(39) + "CLN" + Chr(39) SQLString = SQLString + " where Clinics.Branch = " + Chr(39) + Branch + Chr(39) SQLString = SQLString + " order by shortname"

GenAdapter.SelectCommand.CommandText = SQLString
Clinics.Clinics.Clear()

Try
GenAdapter.Fill(Clinics.Clinics)
Catch e1 As Exception
MsgBox("Error filling ClinicsDataSet" + Chr(10) + e1.Message, MsgBoxStyle.OKOnly) End Try

Jul 21 '05 #12
Your Get/Set statement is what I"m referring to. If the value it's
'getting' from the dataset returns DbNull, and you try returning it, it'll
blow up because the property is of Type String and it can't be converted.
Instead, you might want to do the IsDbNull check inside the Get statement
and if it is DbNull, return sting.Empty for instance.
"Jim" <an*******@discussions.microsoft.com> wrote in message
news:E8**********************************@microsof t.com...
William,

Thank you for the reply.

I tried the message box and got the same error. WorkPhone is a string.

What specifically do you mean by the 'accessor'? Are you referring to the SQL statement that retrieves the data or the xml code for the dataset or the
MS generated .vb code that gets the values as properties from the dataset or
something else that I do not know about? I am including below the xml, the
sql statement for the fill, and a snippet from the code that retrieves the
data from the dataset. The error 13 is generated furhter down in the code
in the same subroutine that does the fill.
We may have a very basic misunderstanding of the proper usage of the development environment to define datasets.
We use an SQLDataAdapter and reconfigure the GenAdapter selectcommand.commandtext depending on the data we are retrieving. The
dataset has been defined by setting the adapter's select command, then
generating the dataset. At execution time we do a fill of the appropriate
dataset. Here is a copy of the xml from one of the datasets that we are
having trouble with.

<?xml version="1.0" standalone="yes" ?><xs:schema id="Clinics" targetNamespace="http://www.tempuri.org/Clinics.xsd"
xmlns:mstns="http://www.tempuri.org/Clinics.xsd" xmlns="http://www.tempuri.org/Clinics.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" attributeFormDefault="qualified" elementFormDefault="qualified"><xs:element
name="Clinics" msdata:IsDataSet="true"><xs:complexType><xs:choice
maxOccurs="unbounded"><xs:element
name="Clinics"><xs:complexType><xs:sequence><xs:el ement name="ClinicNum"
type="xs:short" /><xs:element name="ClinicID" type="xs:string" /><xs:element
name="ShortName" type="xs:string" /><xs:element name="LongName"
type="xs:string" /><xs:element name="Root" type="xs:short" /><xs:element
name="Group" type="xs:string" /><xs:element name="Discount" type="xs:string"
/><xs:element name="License" type="xs:string" /><xs:element name="Doctor"
type="xs:string" /><xs:element name="DirectorName" type="xs:string"
/><xs:element name="DirectorTitle" type="xs:string" /><xs:element
name="webURL" type="xs:string" /><xs:element name="AltContact"
type="xs:string" /><xs:element name="AltContactTitle" type="xs:string"
/><xs:element name="Billing" type="xs:string" /><xs:element name="Expr1"
type="xs:string" /><xs:element name="Expr2" type="xs:dateTime" /><xs:element
name="Expr3" type="xs:short" /><xs:element name="Expr4"
msdata:ReadOnly="true" msdata:AutoIncrement="true" type="xs:int"
/><xs:element name="Expr5" type="xs:int" /><xs:element name="BtBID"
type="xs:int" /><xs:element name="branch" type="xs:string" /><xs:element
name="addresstype" type="xs:string" /><xs:element name="addressline1"
type="xs:string" /><xs:element name="streetnum" type="xs:string"
/><xs:element name="Streetname" type="xs:string" /><xs:element name="Apt"
type="xs:string" /><xs:element name="City" type="xs:string" /><xs:element
name="State" type="xs:string" /><xs:element name="Postalcode"
type="xs:string" /><xs:element name="Latitude" type="xs:string"
/><xs:element name="Longitude" type="xs:string" /><xs:element name="County"
type="xs:string" /><xs:element name="Homephone" type="xs:string"
/><xs:element name="Workphone" type="xs:string" /><xs:element name="FAX"
type="xs:string" /><xs:element name="Pager" type="xs:string" /><xs:element
name="email" type="xs:string" /><xs:element name="altphone" type="xs:string"
/><xs:element name="AltFAX" type="xs:string" /><xs:element name="AltPager"
type="xs:string" /><xs:element name="altemail" type="xs:string"
/><xs:element name="Startdate" type="xs:dateTime" /><xs:element
name="Enddate" type="xs:dateTime" /><xs:element name="Entrydate"
type="xs:dateTime" /><xs:element name="EnteredBy" type="xs:short"
/></xs:sequence></xs:complexType></xs:element></xs:choice></xs:complexType><
xs:unique name="Constraint1" msdata:PrimaryKey="true"><xs:selector
xpath=".//mstns:Clinics" /><xs:field xpath="mstns:Expr5" /><xs:field
xpath="mstns:addresstype" /></xs:unique></xs:element></xs:schema>

And here is the code that retrieves the data from the dataset This is a snippet from Clinics.vb
Public Property Workphone As String
Get
Return CType(Me(Me.tableClinics.WorkphoneColumn),String)
End Get
Set
Me(Me.tableClinics.WorkphoneColumn) = value
End Set
End Property

Finally, here is the sql string and subsequent code used to fill the dataset.
SQLString = "SELECT * FROM clinics "
SQLString = SQLString + " left Join Address on Address.BtBiD=Clinics.BtbID" SQLString = SQLString + " And AddressType=" + Chr(39) + "CLN" + Chr(39) SQLString = SQLString + " where Clinics.Branch = " + Chr(39) + Branch + Chr(39) SQLString = SQLString + " order by shortname"

GenAdapter.SelectCommand.CommandText = SQLString
Clinics.Clinics.Clear()

Try
GenAdapter.Fill(Clinics.Clinics)
Catch e1 As Exception
MsgBox("Error filling ClinicsDataSet" + Chr(10) + e1.Message, MsgBoxStyle.OKOnly) End Try

Jul 21 '05 #13
Jim
Cor

Sorry but that did not help

Ji

Jul 21 '05 #14
Jim
Cor

Sorry but that did not help

Ji

Jul 21 '05 #15
Jim

Jul 21 '05 #16
Jim

Jul 21 '05 #17
Hi Jim,

Strange, I did try this (with some different names, for that can be typos_
\\\
Me.SqlDataAdapter1.Fill(DataSet12)
If IsDBNull(DataSet12.Tables(0).Rows(0)("ident2")) Then
MessageBox.Show("First")
End If
Dim myfield1 As String = DataSet12.Tables(0).Rows(0).ToString
Try
Dim myfield2 As String = DataSet12.pers(0).ident2
Catch ex As System.Data.StrongTypingException
MessageBox.Show("Second")
End Try
///

It did show in the messagebox first First and then Second

I do not understand why this does not work for you?

Cor
Jul 21 '05 #18
Hi Jim,

Strange, I did try this (with some different names, for that can be typos_
\\\
Me.SqlDataAdapter1.Fill(DataSet12)
If IsDBNull(DataSet12.Tables(0).Rows(0)("ident2")) Then
MessageBox.Show("First")
End If
Dim myfield1 As String = DataSet12.Tables(0).Rows(0).ToString
Try
Dim myfield2 As String = DataSet12.pers(0).ident2
Catch ex As System.Data.StrongTypingException
MessageBox.Show("Second")
End Try
///

It did show in the messagebox first First and then Second

I do not understand why this does not work for you?

Cor
Jul 21 '05 #19
I'd really look to get rid of those joins, a datarelation is one of the
coolest objects in ADO.NET and could help eliminate this. You can set the
DefaultValue of your datacolumns which may help you out.
"Jim" <an*******@discussions.microsoft.com> wrote in message
news:72**********************************@microsof t.com...
William

I am aware that the get statement returns the value. I did not know that it was referred to as the 'accessor'. Thanks for the information.
There are many fields throughout the application that can have dbnulls returned when a left or right join is done. If it is necessary to make
changes to the get statement for each accessor, this can become a huge and
error prone task I have done this in the past and as soon as a change to
the dataset was made, the generated accessor code lost my changes.
There has to be a better way to do this. Enclosing the vb code in a try block and detecting error 13 works but is also a real pain. Building a
stored procedure that ensures the joins will return something other than
dbnulls is another possibility but also quite time consuming.
I am wondering if there may be a global property for datasets that causes nulls to be converted to blanks, 0s, etc corresponding to the datatype.
Maybe this is a 'feature' that MS has not yet implemented.

Jim

Jul 21 '05 #20

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

Similar topics

4
by: Jim | last post by:
I am having a problem with the IsDBNull function. When it checks what type of value is contained in the parameter that is passed to it, it does not successfully determine that it has a DBNull...
4
by: BillG | last post by:
I have the following line in my code paid.MonthsPaid = IIf(IsDBNull(Row("MonthsPaid")), Integer.MinValue, Convert.ToInt16(Row("MonthsPaid"))) and I get the error message Object cannot be...
5
by: luna | last post by:
how to i use isdbnull on two tables ? im pulling out the data with a stored procedure like this :- CREATE PROCEDURE search @search varchar(8) AS
3
by: Paul D. Fox | last post by:
I have this code snippet below where I'm loading all the labels based upon the retrieved record from the DataReader. Unfortunatley, some of the values are null, so I can't explicitly set the...
22
by: jim | last post by:
This line of code returns error 13, cast from 'DBNull' to type 'String' is not valid If IsDBNull(Clinics.Clinics.Item(A).Workphone) The <other code End I Clinics.Clinics is a dataset that...
4
by: sck10 | last post by:
Hello (converting from vb to c#), Is there a way to test the value of null of a particular field of a dataset from SQL Server? I am going through a dataset and trying to determine if the value...
4
by: Brad Isaacs | last post by:
I am using ASP.NET 2.0 codebehind Visual Basic, Visual Studio 2005 Working with DataSet creating a Data Access Layer via VS 2005. My error is when the code that is prewritten by VS 2005 Casts...
2
by: Brad Isaacs | last post by:
ASp.NET 2.0 , Visual Studio 2005 I am working with the Add NEw Item >DataSet I have created my Dataset and call it, when I run my project, I receive an error message because the dataset is...
5
by: Rainer Queck | last post by:
Hello NG, I have a typed dataset, where I want to check the column of a datarow if it is DBNull. How can the following code cause an Exception (what is does): if...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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,...

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.