Home All Groups Group Topic Archive Search About
Author
26 Nov 2007 12:52 PM
Emre DÝNÇER
Dear All,
is it possible to extract the DataColumn which is a foreign key of another
table.

foreach (DataRelation dr in dsIlce.Tables[0].ParentRelations) {

Console.WriteLine("123");

console.WriteLine(dr.ParentTable.TableName.ToString());

}

prints nothing unfortunately..



thanks in advance

emre dincer

Author
26 Nov 2007 2:58 PM
MrSmersh
Try the sample you find here:
http://msdn2.microsoft.com/en-US/library/system.data.datatable.parentrelations.aspx

Show quote
"Emre DÝNÇER" wrote:

> Dear All,
> is it possible to extract the DataColumn which is a foreign key of another
> table.
>
> foreach (DataRelation dr in dsIlce.Tables[0].ParentRelations) {
>
> Console.WriteLine("123");
>
> console.WriteLine(dr.ParentTable.TableName.ToString());
>
> }
>
> prints nothing unfortunately..
>
>
>
> thanks in advance
>
> emre dincer
>
>
>
Author
28 Nov 2007 10:10 AM
Emre DÝNÇER
actually i think i was unable to clarify my problem,
the situation is the dataTable belongs to a single table and the DataSet
class does not any
DataRelation object , what i am trying to do is to realize the foreign key
relationship at runtime.
that is i can not utilize DataRelation property.
i think i need another option to realize that a column represents a foreign
key
thanks in advance.
emre dincer
Show quote
"MrSmersh" <MrSme***@discussions.microsoft.com> wrote in message
news:F83BF6D0-BFBF-4F72-9AC5-510F41236EA5@microsoft.com...
> Try the sample you find here:
> http://msdn2.microsoft.com/en-US/library/system.data.datatable.parentrelations.aspx
>
> "Emre DYNÇER" wrote:
>
>> Dear All,
>> is it possible to extract the DataColumn which is a foreign key of
>> another
>> table.
>>
>> foreach (DataRelation dr in dsIlce.Tables[0].ParentRelations) {
>>
>> Console.WriteLine("123");
>>
>> console.WriteLine(dr.ParentTable.TableName.ToString());
>>
>> }
>>
>> prints nothing unfortunately..
>>
>>
>>
>> thanks in advance
>>
>> emre dincer
>>
>>
>>
Author
28 Nov 2007 11:01 AM
MrSmersh
I'm afraid that I do not understand now...
Could you please explain again what you are trying to do?

Show quote
"Emre DÝNÇER" wrote:

> actually i think i was unable to clarify my problem,
> the situation is the dataTable belongs to a single table and the DataSet
> class does not any
> DataRelation object , what i am trying to do is to realize the foreign key
> relationship at runtime.
> that is i can not utilize DataRelation property.
> i think i need another option to realize that a column represents a foreign
> key
> thanks in advance.
> emre dincer
> "MrSmersh" <MrSme***@discussions.microsoft.com> wrote in message
> news:F83BF6D0-BFBF-4F72-9AC5-510F41236EA5@microsoft.com...
> > Try the sample you find here:
> > http://msdn2.microsoft.com/en-US/library/system.data.datatable.parentrelations.aspx
> >
> > "Emre DYNÇER" wrote:
> >
> >> Dear All,
> >> is it possible to extract the DataColumn which is a foreign key of
> >> another
> >> table.
> >>
> >> foreach (DataRelation dr in dsIlce.Tables[0].ParentRelations) {
> >>
> >> Console.WriteLine("123");
> >>
> >> console.WriteLine(dr.ParentTable.TableName.ToString());
> >>
> >> }
> >>
> >> prints nothing unfortunately..
> >>
> >>
> >>
> >> thanks in advance
> >>
> >> emre dincer
> >>
> >>
> >>
>
>
>
Author
28 Nov 2007 12:14 PM
Emre DÝNÇER
Thanks for your interest.
What i am trying to say is I dont declare any DataRelation object at design
time
and at runtime i have the instance of the DataSet  , with these at hand , i
want to catch if one of the columns of datatable of the dataset is a foreign
key of another table.
DSCities dc=new DSCities(); //the dataset for the CitiesTable




"MrSmersh" <MrSme***@discussions.microsoft.com> wrote in message
news:52B01D15-F793-4353-A32E-F624190134DA@microsoft.com...
> I'm afraid that I do not understand now...
> Could you please explain again what you are trying to do?
foreach (DataColumn dc in dc.Tables[0]) {
    //want to realize if the column is a FK...
}
best regards
emre
Show quote
>
> "Emre DYNÇER" wrote:
>
>> actually i think i was unable to clarify my problem,
>> the situation is the dataTable belongs to a single table and the DataSet
>> class does not any
>> DataRelation object , what i am trying to do is to realize the foreign
>> key
>> relationship at runtime.
>> that is i can not utilize DataRelation property.
>> i think i need another option to realize that a column represents a
>> foreign
>> key
>> thanks in advance.
>> emre dincer
>> "MrSmersh" <MrSme***@discussions.microsoft.com> wrote in message
>> news:F83BF6D0-BFBF-4F72-9AC5-510F41236EA5@microsoft.com...
>> > Try the sample you find here:
>> > http://msdn2.microsoft.com/en-US/library/system.data.datatable.parentrelations.aspx
>> >
>> > "Emre DYNÇER" wrote:
>> >
>> >> Dear All,
>> >> is it possible to extract the DataColumn which is a foreign key of
>> >> another
>> >> table.
>> >>
>> >> foreach (DataRelation dr in dsIlce.Tables[0].ParentRelations) {
>> >>
>> >> Console.WriteLine("123");
>> >>
>> >> console.WriteLine(dr.ParentTable.TableName.ToString());
>> >>
>> >> }
>> >>
>> >> prints nothing unfortunately..
>> >>
>> >>
>> >>
>> >> thanks in advance
>> >>
>> >> emre dincer
>> >>
>> >>
>> >>
>>
>>
>>
Author
28 Nov 2007 2:44 PM
MrSmersh
OK, I now understand even less.
How do you “fill” the dataset?
If the database used is SQL Server ADO.Net is able to give you catalog
information’s, hence a dataset with a corresponding structure, all this at
runtime. Otherwise what you put into the dataset you will have.


Show quote
"Emre DÝNÇER" wrote:

> Thanks for your interest.
> What i am trying to say is I dont declare any DataRelation object at design
> time
> and at runtime i have the instance of the DataSet  , with these at hand , i
> want to catch if one of the columns of datatable of the dataset is a foreign
> key of another table.
> DSCities dc=new DSCities(); //the dataset for the CitiesTable
>
>
>
>
> "MrSmersh" <MrSme***@discussions.microsoft.com> wrote in message
> news:52B01D15-F793-4353-A32E-F624190134DA@microsoft.com...
> > I'm afraid that I do not understand now...
> > Could you please explain again what you are trying to do?
> foreach (DataColumn dc in dc.Tables[0]) {
>     //want to realize if the column is a FK...
> }
> best regards
> emre
> >
> > "Emre DYNÇER" wrote:
> >
> >> actually i think i was unable to clarify my problem,
> >> the situation is the dataTable belongs to a single table and the DataSet
> >> class does not any
> >> DataRelation object , what i am trying to do is to realize the foreign
> >> key
> >> relationship at runtime.
> >> that is i can not utilize DataRelation property.
> >> i think i need another option to realize that a column represents a
> >> foreign
> >> key
> >> thanks in advance.
> >> emre dincer
> >> "MrSmersh" <MrSme***@discussions.microsoft.com> wrote in message
> >> news:F83BF6D0-BFBF-4F72-9AC5-510F41236EA5@microsoft.com...
> >> > Try the sample you find here:
> >> > http://msdn2.microsoft.com/en-US/library/system.data.datatable.parentrelations.aspx
> >> >
> >> > "Emre DYNÇER" wrote:
> >> >
> >> >> Dear All,
> >> >> is it possible to extract the DataColumn which is a foreign key of
> >> >> another
> >> >> table.
> >> >>
> >> >> foreach (DataRelation dr in dsIlce.Tables[0].ParentRelations) {
> >> >>
> >> >> Console.WriteLine("123");
> >> >>
> >> >> console.WriteLine(dr.ParentTable.TableName.ToString());
> >> >>
> >> >> }
> >> >>
> >> >> prints nothing unfortunately..
> >> >>
> >> >>
> >> >>
> >> >> thanks in advance
> >> >>
> >> >> emre dincer
> >> >>
> >> >>
> >> >>
> >>
> >>
> >>
>
>
>
Author
29 Nov 2007 1:39 PM
Emre DÝNÇER
Hello Again,

i fill the ds in the following manner.





public DataSet VeriGetir(string ssql,string sTableName,bool bFillSchema)

{

OpenConnection();

SqlDataAdapter da = new SqlDataAdapter(ssql, mConnection);

try

{

DataSet ds = new DataSet();

if (mIsTransactional)

da.SelectCommand.Transaction = mTransaction;

if (bFillSchema)

da.FillSchema(ds, SchemaType.Source, sTableName);

da.Fill(ds, sTableName);

return ds;

}

catch (Exception ex)

{

HataLogla(ex,ssql);

throw (ex);

}

finally

{

CloseConnection();

}

}

Show quote
"MrSmersh" <MrSme***@discussions.microsoft.com> wrote in message
news:B627E65E-E904-4A82-8065-DCADD2CF5425@microsoft.com...
> OK, I now understand even less.
> How do you "fill" the dataset?
> If the database used is SQL Server ADO.Net is able to give you catalog
> information's, hence a dataset with a corresponding structure, all this at
> runtime. Otherwise what you put into the dataset you will have.
>
>
> "Emre DYNÇER" wrote:
>
>> Thanks for your interest.
>> What i am trying to say is I dont declare any DataRelation object at
>> design
>> time
>> and at runtime i have the instance of the DataSet  , with these at hand ,
>> i
>> want to catch if one of the columns of datatable of the dataset is a
>> foreign
>> key of another table.
>> DSCities dc=new DSCities(); //the dataset for the CitiesTable
>>
>>
>>
>>
>> "MrSmersh" <MrSme***@discussions.microsoft.com> wrote in message
>> news:52B01D15-F793-4353-A32E-F624190134DA@microsoft.com...
>> > I'm afraid that I do not understand now...
>> > Could you please explain again what you are trying to do?
>> foreach (DataColumn dc in dc.Tables[0]) {
>>     //want to realize if the column is a FK...
>> }
>> best regards
>> emre
>> >
>> > "Emre DYNÇER" wrote:
>> >
>> >> actually i think i was unable to clarify my problem,
>> >> the situation is the dataTable belongs to a single table and the
>> >> DataSet
>> >> class does not any
>> >> DataRelation object , what i am trying to do is to realize the foreign
>> >> key
>> >> relationship at runtime.
>> >> that is i can not utilize DataRelation property.
>> >> i think i need another option to realize that a column represents a
>> >> foreign
>> >> key
>> >> thanks in advance.
>> >> emre dincer
>> >> "MrSmersh" <MrSme***@discussions.microsoft.com> wrote in message
>> >> news:F83BF6D0-BFBF-4F72-9AC5-510F41236EA5@microsoft.com...
>> >> > Try the sample you find here:
>> >> > http://msdn2.microsoft.com/en-US/library/system.data.datatable.parentrelations.aspx
>> >> >
>> >> > "Emre DYNÇER" wrote:
>> >> >
>> >> >> Dear All,
>> >> >> is it possible to extract the DataColumn which is a foreign key of
>> >> >> another
>> >> >> table.
>> >> >>
>> >> >> foreach (DataRelation dr in dsIlce.Tables[0].ParentRelations) {
>> >> >>
>> >> >> Console.WriteLine("123");
>> >> >>
>> >> >> console.WriteLine(dr.ParentTable.TableName.ToString());
>> >> >>
>> >> >> }
>> >> >>
>> >> >> prints nothing unfortunately..
>> >> >>
>> >> >>
>> >> >>
>> >> >> thanks in advance
>> >> >>
>> >> >> emre dincer
>> >> >>
>> >> >>
>> >> >>
>> >>
>> >>
>> >>
>>
>>
>>
Author
29 Nov 2007 8:23 PM
MrSmersh
OK I must recognize that I said something stupid, ADO.Net does not fill the
relations info.
Mea culpa X3.
You have 2 workarounds use OleDBConnection as shown here OleDBConnection
http://weblogs.asp.net/rosherove/archive/2003/06/29/9542.aspx or fill the
dataset as now and add the missing relations using the catalog stored
procedure (for SQL Server other databases uses catalog tables) sp_fkeys.


Show quote
"Emre DÝNÇER" wrote:

> Hello Again,
>
> i fill the ds in the following manner.
>
>
>
>
>
> public DataSet VeriGetir(string ssql,string sTableName,bool bFillSchema)
>
> {
>
> OpenConnection();
>
> SqlDataAdapter da = new SqlDataAdapter(ssql, mConnection);
>
> try
>
> {
>
> DataSet ds = new DataSet();
>
> if (mIsTransactional)
>
> da.SelectCommand.Transaction = mTransaction;
>
> if (bFillSchema)
>
> da.FillSchema(ds, SchemaType.Source, sTableName);
>
> da.Fill(ds, sTableName);
>
> return ds;
>
> }
>
> catch (Exception ex)
>
> {
>
> HataLogla(ex,ssql);
>
> throw (ex);
>
> }
>
> finally
>
> {
>
> CloseConnection();
>
> }
>
> }
>
> "MrSmersh" <MrSme***@discussions.microsoft.com> wrote in message
> news:B627E65E-E904-4A82-8065-DCADD2CF5425@microsoft.com...
> > OK, I now understand even less.
> > How do you "fill" the dataset?
> > If the database used is SQL Server ADO.Net is able to give you catalog
> > information's, hence a dataset with a corresponding structure, all this at
> > runtime. Otherwise what you put into the dataset you will have.
> >
> >
> > "Emre DYNÇER" wrote:
> >
> >> Thanks for your interest.
> >> What i am trying to say is I dont declare any DataRelation object at
> >> design
> >> time
> >> and at runtime i have the instance of the DataSet  , with these at hand ,
> >> i
> >> want to catch if one of the columns of datatable of the dataset is a
> >> foreign
> >> key of another table.
> >> DSCities dc=new DSCities(); //the dataset for the CitiesTable
> >>
> >>
> >>
> >>
> >> "MrSmersh" <MrSme***@discussions.microsoft.com> wrote in message
> >> news:52B01D15-F793-4353-A32E-F624190134DA@microsoft.com...
> >> > I'm afraid that I do not understand now...
> >> > Could you please explain again what you are trying to do?
> >> foreach (DataColumn dc in dc.Tables[0]) {
> >>     //want to realize if the column is a FK...
> >> }
> >> best regards
> >> emre
> >> >
> >> > "Emre DYNÇER" wrote:
> >> >
> >> >> actually i think i was unable to clarify my problem,
> >> >> the situation is the dataTable belongs to a single table and the
> >> >> DataSet
> >> >> class does not any
> >> >> DataRelation object , what i am trying to do is to realize the foreign
> >> >> key
> >> >> relationship at runtime.
> >> >> that is i can not utilize DataRelation property.
> >> >> i think i need another option to realize that a column represents a
> >> >> foreign
> >> >> key
> >> >> thanks in advance.
> >> >> emre dincer
> >> >> "MrSmersh" <MrSme***@discussions.microsoft.com> wrote in message
> >> >> news:F83BF6D0-BFBF-4F72-9AC5-510F41236EA5@microsoft.com...
> >> >> > Try the sample you find here:
> >> >> > http://msdn2.microsoft.com/en-US/library/system.data.datatable.parentrelations.aspx
> >> >> >
> >> >> > "Emre DYNÇER" wrote:
> >> >> >
> >> >> >> Dear All,
> >> >> >> is it possible to extract the DataColumn which is a foreign key of
> >> >> >> another
> >> >> >> table.
> >> >> >>
> >> >> >> foreach (DataRelation dr in dsIlce.Tables[0].ParentRelations) {
> >> >> >>
> >> >> >> Console.WriteLine("123");
> >> >> >>
> >> >> >> console.WriteLine(dr.ParentTable.TableName.ToString());
> >> >> >>
> >> >> >> }
> >> >> >>
> >> >> >> prints nothing unfortunately..
> >> >> >>
> >> >> >>
> >> >> >>
> >> >> >> thanks in advance
> >> >> >>
> >> >> >> emre dincer
> >> >> >>
> >> >> >>
> >> >> >>
> >> >>
> >> >>
> >> >>
> >>
> >>
> >>
>
>
>

AddThis Social Bookmark Button