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 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
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
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
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
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
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
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
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
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
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
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
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
Cor
Sorry but that did not help
Ji
Cor
Sorry but that did not help
Ji
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
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
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...
|
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,...
|
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...
|
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...
| |