PC Review


Reply
Thread Tools Rate Thread

Datarelation between different column types

 
 
Jason James
Guest
Posts: n/a
 
      4th Aug 2005
Hi,

I am trying to create a new datarelation between columns
in two tables. The data types of the columns are Integer
and Double, and when I try and create the data relation
I get an invalid constraint exception thrown that says:

Parent columns and child columns don't have type- matching columns'

Is there anyway of getting around this issue, other than
changing the types of the columns? I am linking to the
data using an MS Access database (the data is an ODBC source)
and so I can't change the type!

Even though the type of the column that MS Access has
linked to is Double, it does in fact only contain integer
values.

Many thanks,

Jason.
 
Reply With Quote
 
 
 
 
Miha Markic [MVP C#]
Guest
Posts: n/a
 
      4th Aug 2005
Hi Jason,

Did you try changing just DataColumn's type from double to integer?

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/
SLODUG - Slovene Developer Users Group www.codezone-si.info

"Jason James" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
>
> I am trying to create a new datarelation between columns
> in two tables. The data types of the columns are Integer
> and Double, and when I try and create the data relation
> I get an invalid constraint exception thrown that says:
>
> Parent columns and child columns don't have type- matching columns'
>
> Is there anyway of getting around this issue, other than
> changing the types of the columns? I am linking to the
> data using an MS Access database (the data is an ODBC source)
> and so I can't change the type!
>
> Even though the type of the column that MS Access has
> linked to is Double, it does in fact only contain integer
> values.
>
> Many thanks,
>
> Jason.



 
Reply With Quote
 
Jason James
Guest
Posts: n/a
 
      4th Aug 2005
Can I do this in VB.Net? I can't change the type in the linked
field as Access won't let me!

I'll give it a go and let you know.

Thanks,

Jason

On Thu, 4 Aug 2005 09:52:22 +0200, "Miha Markic [MVP C#]" <miha at
rthand com> wrote:

>Hi Jason,
>
>Did you try changing just DataColumn's type from double to integer?
>
>--
>Miha Markic [MVP C#] - RightHand .NET consulting & development
>www.rthand.com
>Blog: http://cs.rthand.com/blogs/blog_with_righthand/
>SLODUG - Slovene Developer Users Group www.codezone-si.info
>
>"Jason James" <(E-Mail Removed)> wrote in message
>news:(E-Mail Removed)...
>> Hi,
>>
>> I am trying to create a new datarelation between columns
>> in two tables. The data types of the columns are Integer
>> and Double, and when I try and create the data relation
>> I get an invalid constraint exception thrown that says:
>>
>> Parent columns and child columns don't have type- matching columns'
>>
>> Is there anyway of getting around this issue, other than
>> changing the types of the columns? I am linking to the
>> data using an MS Access database (the data is an ODBC source)
>> and so I can't change the type!
>>
>> Even though the type of the column that MS Access has
>> linked to is Double, it does in fact only contain integer
>> values.
>>
>> Many thanks,
>>
>> Jason.

>
>


 
Reply With Quote
 
Jason James
Guest
Posts: n/a
 
      4th Aug 2005
Miha,

I got there in the end. I had to load the schema of the data into the
dataset first, as you can't modify a datatype once the field contains
data. Once I'd loaded the schema and then modified the field,
and then loaded the actual data I was able to add the data relation.

Many thanks,

Jason.

On Thu, 4 Aug 2005 09:52:22 +0200, "Miha Markic [MVP C#]" <miha at
rthand com> wrote:

>Hi Jason,
>
>Did you try changing just DataColumn's type from double to integer?
>
>--
>Miha Markic [MVP C#] - RightHand .NET consulting & development
>www.rthand.com
>Blog: http://cs.rthand.com/blogs/blog_with_righthand/
>SLODUG - Slovene Developer Users Group www.codezone-si.info
>
>"Jason James" <(E-Mail Removed)> wrote in message
>news:(E-Mail Removed)...
>> Hi,
>>
>> I am trying to create a new datarelation between columns
>> in two tables. The data types of the columns are Integer
>> and Double, and when I try and create the data relation
>> I get an invalid constraint exception thrown that says:
>>
>> Parent columns and child columns don't have type- matching columns'
>>
>> Is there anyway of getting around this issue, other than
>> changing the types of the columns? I am linking to the
>> data using an MS Access database (the data is an ODBC source)
>> and so I can't change the type!
>>
>> Even though the type of the column that MS Access has
>> linked to is Double, it does in fact only contain integer
>> values.
>>
>> Many thanks,
>>
>> Jason.

>
>


 
Reply With Quote
 
AMDRIT
Guest
Posts: n/a
 
      4th Aug 2005
If you didn't want to use a strongly typed dataset:

Sample #1 (you could have specified the data format you wanted for each
column.)

dataapater1.selectcommand.commandtext = "Select cdbl(column1) as column1,
column2, column3 from parenttable"
dataapater2.selectcommand.commandtext = "Select column1, column2,
cdbl(column3) as column3 from childtable"

ds.Relations.Add(New DataRelation("ParentChild", dt1.Columns(0),
dt2.Columns("Column3"), True))

Sample #2 (you could have defined the table first, then load it all via
code.)

Using the strongly typed dataset generator, a lot of work is done for you
with a couple clicks of the mouse.
Here is one manual way of doing it.

Dim ds As DataSet
Dim dt1 As DataTable, dt2 As DataTable

'Instantiate the dataset
ds = New DataSet("Warehouse")

'Instantiate teh datatables
dt1 = New DataTable("MyParentTable")
dt2 = New DataTable("MyChildTable")

'Add the tables to the set
ds.Tables.Add(dt1)
ds.Tables.Add(dt2)

'Define the first table's columns
dt1.Columns.Add(New DataColumn("column1", GetType(System.Double)))
dt1.Columns.Add(New DataColumn("column2", GetType(System.String)))

'Create a Primary Key

dt1.PrimaryKey = New DataColumn() {dt1.Columns(0)}

'Define the second table's columns
dt2.Columns.Add(New DataColumn("column1", GetType(System.Int32)))
dt2.Columns.Add(New DataColumn("column2", GetType(System.String)))
dt2.Columns.Add(New DataColumn("column3", GetType(System.Double)))

'Create a Primary Key
dt1.PrimaryKey = New DataColumn() {dt1.Columns("Column1")}

'Retrieve the data
mydataadapter1.fill(dt1)
mydataadapter2.fill(dt2)

'Create Relationship
ds.Relations.Add(New DataRelation("ParentChild", dt1.Columns(0),
dt2.Columns("Column3"), True))


"Jason James" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Miha,
>
> I got there in the end. I had to load the schema of the data into the
> dataset first, as you can't modify a datatype once the field contains
> data. Once I'd loaded the schema and then modified the field,
> and then loaded the actual data I was able to add the data relation.
>
> Many thanks,
>
> Jason.
>
> On Thu, 4 Aug 2005 09:52:22 +0200, "Miha Markic [MVP C#]" <miha at
> rthand com> wrote:
>
>>Hi Jason,
>>
>>Did you try changing just DataColumn's type from double to integer?
>>
>>--
>>Miha Markic [MVP C#] - RightHand .NET consulting & development
>>www.rthand.com
>>Blog: http://cs.rthand.com/blogs/blog_with_righthand/
>>SLODUG - Slovene Developer Users Group www.codezone-si.info
>>
>>"Jason James" <(E-Mail Removed)> wrote in message
>>news:(E-Mail Removed)...
>>> Hi,
>>>
>>> I am trying to create a new datarelation between columns
>>> in two tables. The data types of the columns are Integer
>>> and Double, and when I try and create the data relation
>>> I get an invalid constraint exception thrown that says:
>>>
>>> Parent columns and child columns don't have type- matching columns'
>>>
>>> Is there anyway of getting around this issue, other than
>>> changing the types of the columns? I am linking to the
>>> data using an MS Access database (the data is an ODBC source)
>>> and so I can't change the type!
>>>
>>> Even though the type of the column that MS Access has
>>> linked to is Double, it does in fact only contain integer
>>> values.
>>>
>>> Many thanks,
>>>
>>> Jason.

>>
>>

>



 
Reply With Quote
 
Jason James
Guest
Posts: n/a
 
      5th Aug 2005
I like the first suggestion, and casting the field to a different type
before you execute the SELECT query is a nice way of solving
the problem.

Many thanks,

Jason.

On Thu, 4 Aug 2005 09:06:36 -0500, "AMDRIT" <(E-Mail Removed)>
wrote:

>If you didn't want to use a strongly typed dataset:
>
>Sample #1 (you could have specified the data format you wanted for each
>column.)
>
> dataapater1.selectcommand.commandtext = "Select cdbl(column1) as column1,
>column2, column3 from parenttable"
> dataapater2.selectcommand.commandtext = "Select column1, column2,
>cdbl(column3) as column3 from childtable"
>
> ds.Relations.Add(New DataRelation("ParentChild", dt1.Columns(0),
>dt2.Columns("Column3"), True))
>
>Sample #2 (you could have defined the table first, then load it all via
>code.)
>
> Using the strongly typed dataset generator, a lot of work is done for you
>with a couple clicks of the mouse.
> Here is one manual way of doing it.
>
> Dim ds As DataSet
> Dim dt1 As DataTable, dt2 As DataTable
>
> 'Instantiate the dataset
> ds = New DataSet("Warehouse")
>
> 'Instantiate teh datatables
> dt1 = New DataTable("MyParentTable")
> dt2 = New DataTable("MyChildTable")
>
> 'Add the tables to the set
> ds.Tables.Add(dt1)
> ds.Tables.Add(dt2)
>
> 'Define the first table's columns
> dt1.Columns.Add(New DataColumn("column1", GetType(System.Double)))
> dt1.Columns.Add(New DataColumn("column2", GetType(System.String)))
>
> 'Create a Primary Key
>
> dt1.PrimaryKey = New DataColumn() {dt1.Columns(0)}
>
> 'Define the second table's columns
> dt2.Columns.Add(New DataColumn("column1", GetType(System.Int32)))
> dt2.Columns.Add(New DataColumn("column2", GetType(System.String)))
> dt2.Columns.Add(New DataColumn("column3", GetType(System.Double)))
>
> 'Create a Primary Key
> dt1.PrimaryKey = New DataColumn() {dt1.Columns("Column1")}
>
> 'Retrieve the data
> mydataadapter1.fill(dt1)
> mydataadapter2.fill(dt2)
>
> 'Create Relationship
> ds.Relations.Add(New DataRelation("ParentChild", dt1.Columns(0),
>dt2.Columns("Column3"), True))
>
>
>"Jason James" <(E-Mail Removed)> wrote in message
>news:(E-Mail Removed)...
>> Miha,
>>
>> I got there in the end. I had to load the schema of the data into the
>> dataset first, as you can't modify a datatype once the field contains
>> data. Once I'd loaded the schema and then modified the field,
>> and then loaded the actual data I was able to add the data relation.
>>
>> Many thanks,
>>
>> Jason.
>>
>> On Thu, 4 Aug 2005 09:52:22 +0200, "Miha Markic [MVP C#]" <miha at
>> rthand com> wrote:
>>
>>>Hi Jason,
>>>
>>>Did you try changing just DataColumn's type from double to integer?
>>>
>>>--
>>>Miha Markic [MVP C#] - RightHand .NET consulting & development
>>>www.rthand.com
>>>Blog: http://cs.rthand.com/blogs/blog_with_righthand/
>>>SLODUG - Slovene Developer Users Group www.codezone-si.info
>>>
>>>"Jason James" <(E-Mail Removed)> wrote in message
>>>news:(E-Mail Removed)...
>>>> Hi,
>>>>
>>>> I am trying to create a new datarelation between columns
>>>> in two tables. The data types of the columns are Integer
>>>> and Double, and when I try and create the data relation
>>>> I get an invalid constraint exception thrown that says:
>>>>
>>>> Parent columns and child columns don't have type- matching columns'
>>>>
>>>> Is there anyway of getting around this issue, other than
>>>> changing the types of the columns? I am linking to the
>>>> data using an MS Access database (the data is an ODBC source)
>>>> and so I can't change the type!
>>>>
>>>> Even though the type of the column that MS Access has
>>>> linked to is Double, it does in fact only contain integer
>>>> values.
>>>>
>>>> Many thanks,
>>>>
>>>> Jason.
>>>
>>>

>>

>
>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Needed: Chart that combines clustered column and stacked column types Gerry Microsoft Excel Charting 3 14th Feb 2007 02:53 AM
DataRelation Woes!!! Need Help (column argument cannot be null) Hexman Microsoft VB .NET 0 18th Sep 2006 11:55 PM
DataRelation left outer join different database types Peter Microsoft ADO .NET 4 19th Jul 2006 05:36 AM
How do I mix column chart types? =?Utf-8?B?UmFtZXNoIE5hcmFzaW1oYW4=?= Microsoft Excel Charting 1 20th Jul 2005 11:23 PM
Expression Column - DataRelation - Filtering Jo?o P. Bragan?a Microsoft ADO .NET 5 6th May 2004 04:19 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:52 AM.