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

DataRelations w/ different types

I need to create a data relation between two rows in two tables that were
designed poorly years ago. TableA has the ID Number Column as a varchar(50)
array, whereas TableB has the ID Number Column as an integer.

The tables are in production and have several other applications that rely
on them, so they can not simply be changed.

The code below does not work because they two columns are incompatible:
Expand|Select|Wrap|Line Numbers
  1. // ID_Num is type nvarchar(50)
  2. DataColumn dcParent
  3. = m_dataSet.Tables[m_strTableA].Columns["ID_Num"];
  4. // IDNUM is type int
  5. DataColumn dcChild
  6. = m_dataSet.Tables[m_strTableB].Columns["IDNUM"];
  7. DataRelation dr
  8. = new DataRelation("AtoB", dcParent, dcChild);
  9. m_dataSet.Relations.Add(dr);
  10.  
Can a DataRelation be be created with these two columns?
Jun 27 '08 #1
5 1205
Solved my question via a co-worker that knew a lot more about SQL than I did:
In my select clause, I added a cast to the 'int' variable.

After modifying my select statement, the code below works just fine!

"jp2msft" wrote:
I need to create a data relation between two rows in two tables that were
designed poorly years ago. TableA has the ID Number Column as a varchar(50)
array, whereas TableB has the ID Number Column as an integer.

The tables are in production and have several other applications that rely
on them, so they can not simply be changed.

The code below does not work because they two columns are incompatible:
Expand|Select|Wrap|Line Numbers
  1.   // ID_Num is type nvarchar(50)
  2.   DataColumn dcParent
  3.     = m_dataSet.Tables[m_strTableA].Columns["ID_Num"];
  4.   // IDNUM is type int
  5.   DataColumn dcChild
  6.     = m_dataSet.Tables[m_strTableB].Columns["IDNUM"];
  7.   DataRelation dr
  8.     = new DataRelation("AtoB", dcParent, dcChild);
  9.   m_dataSet.Relations.Add(dr);
  10.  

Can a DataRelation be be created with these two columns?
Jun 27 '08 #2
On Jun 13, 2:31*pm, jp2msft <jp2m...@discussions.microsoft.comwrote:
I need to create a data relation between two rows in two tables that were
designed poorly years ago. TableA has the ID Number Column as a varchar(50)
array, whereas TableB has the ID Number Column as an integer.

The tables are in production and have several other applications that rely
on them, so they can not simply be changed.

The code below does not work because they two columns are incompatible:
Expand|Select|Wrap|Line Numbers
  1. * // ID_Num is type nvarchar(50)
  2. * DataColumn dcParent
  3. * * = m_dataSet.Tables[m_strTableA].Columns["ID_Num"];
  4. * // IDNUM is type int
  5. * DataColumn dcChild
  6. * * = m_dataSet.Tables[m_strTableB].Columns["IDNUM"];
  7. * DataRelation dr
  8. * * = new DataRelation("AtoB", dcParent, dcChild);
  9. * m_dataSet.Relations.Add(dr);
  10.  

Can a DataRelation be be created with these two columns?
Why don't you add another column to one of the tables as the other's
table ID type
Jun 27 '08 #3
On Jun 13, 2:59*pm, jp2msft <jp2m...@discussions.microsoft.comwrote:
Solved my question via a co-worker that knew a lot more about SQL than I did:
In my select clause, I added a cast to the 'int' variable.

After modifying my select statement, the code below works just fine!

"jp2msft" wrote:
I need to create a data relation between two rows in two tables that were
designed poorly years ago. TableA has the ID Number Column as a varchar(50)
array, whereas TableB has the ID Number Column as an integer.
The tables are in production and have several other applications that rely
on them, so they can not simply be changed.
The code below does not work because they two columns are incompatible:
Expand|Select|Wrap|Line Numbers
  1.  * // ID_Num is type nvarchar(50)
  2.  * DataColumn dcParent
  3.  * * = m_dataSet.Tables[m_strTableA].Columns["ID_Num"];
  4.  * // IDNUM is type int
  5.  * DataColumn dcChild
  6.  * * = m_dataSet.Tables[m_strTableB].Columns["IDNUM"];
  7.  * DataRelation dr
  8.  * * = new DataRelation("AtoB", dcParent, dcChild);
  9.  * m_dataSet.Relations.Add(dr);
  10.  
Can a DataRelation be be created with these two columns?- Hide quoted text -

- Show quoted text -
Hi,

But then you are modifying the column, which was one of your
constrains.
Jun 27 '08 #4
I can't help the way the table was designed. :)

"Ignacio Machin ( .NET/ C# MVP )" wrote:
But then you are modifying the column, which was one of your
constrains.
Jun 27 '08 #5
Because the tables are in production and we have a lot of 3rd party companies
and their equipment tied into these tables. Modifying table designs often
causes their software to stop, and that stops production.

That's what happens when people write their SQL queries using "SELECT * FROM
TABLE". That wildcard can cause a lot of problems.

"Ignacio Machin ( .NET/ C# MVP )" wrote:
Why don't you add another column to one of the tables as the other's
table ID type
Jun 27 '08 #6

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

Similar topics

1
by: Les | last post by:
I have a problem getting Dataset.WriteXml() to create a nested xml realtionship. All I get is an inline xsd (all nodes are children of the root). Documentation says to use...
2
by: Che | last post by:
Greetings, I am writing an application that uses an extendible XML file. in order to validate that XML I use a main XSD and in additional - few more extensions XSD's that uses the types in the...
0
by: Randy | last post by:
I have two DataTables in a DataSet. I create a DataRelation between two like-typed columns in the first and second tables, and it works exactly as expected. Unfortunately, the default behavior...
1
by: Fleckman | last post by:
I have a DataSet with 14 DataTables and 18 Relationships that were defined within Visual Studio .NET 2003. Everything looks OK in the visual development environment, i.e. when I preview the DataSet...
0
by: George Durzi | last post by:
I have a DataSet with 3 tables, and two DataRelations dsSubs.Tables.TableName = "Subscriptions" dsSubs.Tables.TableName = "AccountManagers" dsSubs.Relations.Add "AccountManagers_Subscriptions",...
3
by: Carlos Albert | last post by:
Hello everybody, I'm using some gridviews with datalists inside template columns. Now, for each datalist I'm calling a method returning a dataset (depending from a column from the gridview). ...
8
by: Born Bugler | last post by:
What I'm actually talking about is, when you put the same class in different assemblies, you get two different types. This is reasonable (if you would call it) in most cases as it avoids possible...
0
by: =?Utf-8?B?cmFuZHkxMjAw?= | last post by:
I'm working in Visual Studio 2005 Team Edition for Software Developers. I have 3 tables defined in the DataSet Designer, and a DataRelation between each table. The user sees a each of these...
0
by: Vajrala Narendra | last post by:
hi all, am working in asp.net i am using two data entry screens for parent and child tables. i heard that using datarelations we can achieve this using single screen. is it ppossible? please...
55
by: tonytech08 | last post by:
How valuable is it that class objects behave like built-in types? I appears that the whole "constructor doesn't return a value because they are called by the compiler" thing is to enable...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.