DataRelations w/ different types

  • Thread starter Thread starter jp2msft
  • Start date Start date
J

jp2msft

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:
Code:
// ID_Num is type nvarchar(50)
DataColumn dcParent
= m_dataSet.Tables[m_strTableA].Columns["ID_Num"];
// IDNUM is type int
DataColumn dcChild
= m_dataSet.Tables[m_strTableB].Columns["IDNUM"];
DataRelation dr
= new DataRelation("AtoB", dcParent, dcChild);
m_dataSet.Relations.Add(dr);

Can a DataRelation be be created with these two columns?
 
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!
 
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:
Code:
  // ID_Num is type nvarchar(50)
  DataColumn dcParent
    = m_dataSet.Tables[m_strTableA].Columns["ID_Num"];
  // IDNUM is type int
  DataColumn dcChild
    = m_dataSet.Tables[m_strTableB].Columns["IDNUM"];
  DataRelation dr
    = new DataRelation("AtoB", dcParent, dcChild);
  m_dataSet.Relations.Add(dr);

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
 
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 said:
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:
Code:
  // ID_Num is type nvarchar(50)
  DataColumn dcParent
    = m_dataSet.Tables[m_strTableA].Columns["ID_Num"];
  // IDNUM is type int
  DataColumn dcChild
    = m_dataSet.Tables[m_strTableB].Columns["IDNUM"];
  DataRelation dr
    = new DataRelation("AtoB", dcParent, dcChild);
  m_dataSet.Relations.Add(dr);
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.
 
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.
 
Back
Top