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.
>>
>>
>