DataRelations w/ different types

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?
 
J

jp2msft

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

Ignacio Machin ( .NET/ C# MVP )

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
 
I

Ignacio Machin ( .NET/ C# MVP )

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

jp2msft

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top