Connecting Tech Pros Worldwide Forums | Help | Site Map

problem: ds.Tables ["xx"].Columns ["xx"] always returns null

Brian
Guest
 
Posts: n/a
#1: Nov 16 '05
This is causing me to not be able to create a relation in my dataset.
Here's my code:

dc1 = ds.Tables ["categories"].Columns ["ID"];
dc2 = ds.Tables ["subcategories"].Columns ["Category_ID"];
dr1 = new System.Data.DataRelation ("categories2subcategories", dc1,
dc2);
ds.Relations.Add (dr1);

dc1 always works fine. dc2 always returns null. There ARE records in
the dc2 table. Any idea why it's returning null?

I can't find any documentation anywhere about this. :(

Thanks in advance for any help.

-Brian

Nicholas Paldino [.NET/C# MVP]
Guest
 
Posts: n/a
#2: Nov 16 '05

re: problem: ds.Tables ["xx"].Columns ["xx"] always returns null


Brian,

Are you saying that the value returned by the call to the indexer of the
object returned by the Columns property returns null? Or do you mean
something else?


--
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com

"Brian" <brian.kiser@ky.gov> wrote in message
news:638274b4.0405270525.2716a37b@posting.google.c om...[color=blue]
> This is causing me to not be able to create a relation in my dataset.
> Here's my code:
>
> dc1 = ds.Tables ["categories"].Columns ["ID"];
> dc2 = ds.Tables ["subcategories"].Columns ["Category_ID"];
> dr1 = new System.Data.DataRelation ("categories2subcategories", dc1,
> dc2);
> ds.Relations.Add (dr1);
>
> dc1 always works fine. dc2 always returns null. There ARE records in
> the dc2 table. Any idea why it's returning null?
>
> I can't find any documentation anywhere about this. :(
>
> Thanks in advance for any help.
>
> -Brian[/color]


Ignacio Machin \( .NET/ C# MVP \)
Guest
 
Posts: n/a
#3: Nov 16 '05

re: problem: ds.Tables ["xx"].Columns ["xx"] always returns null


Hi Brian,
[color=blue]
> dc2 = ds.Tables ["subcategories"].Columns ["Category_ID"];[/color]

Is this the line with the "issue"
if it's so it;s because the column "Category_ID" does not exist in the
"subcategories" table. Check the definition of the table.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Brian" <brian.kiser@ky.gov> wrote in message
news:638274b4.0405270525.2716a37b@posting.google.c om...[color=blue]
> This is causing me to not be able to create a relation in my dataset.
> Here's my code:
>
> dc1 = ds.Tables ["categories"].Columns ["ID"];
> dc2 = ds.Tables ["subcategories"].Columns ["Category_ID"];
> dr1 = new System.Data.DataRelation ("categories2subcategories", dc1,
> dc2);
> ds.Relations.Add (dr1);
>
> dc1 always works fine. dc2 always returns null. There ARE records in
> the dc2 table. Any idea why it's returning null?
>
> I can't find any documentation anywhere about this. :(
>
> Thanks in advance for any help.
>
> -Brian[/color]


Brian Kiser
Guest
 
Posts: n/a
#4: Nov 16 '05

re: problem: ds.Tables ["xx"].Columns ["xx"] always returns null


Hi, Ignacio. Yes, that's the line. The Category_ID field is definitely
in the (Access) table.

It's not a primary key, however. There aren't any rules saying
Category_ID must be the pk, are there? I can't figure out why this line
returns null...



--------------------
Hi Brian,
[color=blue]
> dc2 = ds.Tables ["subcategories"].Columns ["Category_ID"];[/color]

Is this the line with the "issue"
if it's so it;s because the column "Category_ID" does not exist in the
"subcategories" table. Check the definition of the table.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Ignacio Machin \( .NET/ C# MVP \)
Guest
 
Posts: n/a
#5: Nov 16 '05

re: problem: ds.Tables ["xx"].Columns ["xx"] always returns null


Hi Brian,

It should be the PK in the category table, but that's not the problem
though.

if that line return null is cause the column is not found in the table, use
the watch to see if it does exist, check que query that you use to generate
the table, somewhere somehow you are not getting that column from the access
DB.


Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


"Brian Kiser" <brian.kiser@ky.gov> wrote in message
news:ebMxiP$QEHA.2572@TK2MSFTNGP12.phx.gbl...[color=blue]
> Hi, Ignacio. Yes, that's the line. The Category_ID field is definitely
> in the (Access) table.
>
> It's not a primary key, however. There aren't any rules saying
> Category_ID must be the pk, are there? I can't figure out why this line
> returns null...
>
>
>
> --------------------
> Hi Brian,
>[color=green]
> > dc2 = ds.Tables ["subcategories"].Columns ["Category_ID"];[/color]
>
> Is this the line with the "issue"
> if it's so it;s because the column "Category_ID" does not exist in the
> "subcategories" table. Check the definition of the table.
>
> Cheers,
>
> --
> Ignacio Machin,
> ignacio.machin AT dot.state.fl.us
> Florida Department Of Transportation
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it![/color]


Brian Kiser
Guest
 
Posts: n/a
#6: Nov 16 '05

re: problem: ds.Tables ["xx"].Columns ["xx"] always returns null


I'll do some more tracing and try to pinpoint the problem further.

It can't be the pk because it's actually the fk to the Category table.
I'm trying to establish a relationship between the Categories and
Subcategories tables, and it's a 1-to-many relationship, so I can't use
the two pk's from each table.

The interesting thing is, if I substitute the REAL pk of Subcategories
in the statement, instead of "Category_ID", then I don't get any errors.
It doesn't work correctly, because the relationship must be
Categories.pk --> Subcategories.fk, but the statement returns something
other than null.

Weird.


---------------
Hi Brian,

It should be the PK in the category table, but that's not the problem
though.

if that line return null is cause the column is not found in the table,
use
the watch to see if it does exist, check que query that you use to
generate
the table, somewhere somehow you are not getting that column from the
access
DB.


Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Ignacio Machin \( .NET/ C# MVP \)
Guest
 
Posts: n/a
#7: Nov 16 '05

re: problem: ds.Tables ["xx"].Columns ["xx"] always returns null


Hi Brian,
[color=blue]
> It can't be the pk because it's actually the fk to the Category table.[/color]

That's what I meant, sorry for not specify it.

[color=blue]
> The interesting thing is, if I substitute the REAL pk of Subcategories
> in the statement, instead of "Category_ID", then I don't get any errors.[/color]

Again, let's focus in your current problem, it's not a matter of
relationship, but it's that the column is not found in the Colums collection
of the table.


Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


Brian Kiser
Guest
 
Posts: n/a
#8: Nov 16 '05

re: problem: ds.Tables ["xx"].Columns ["xx"] always returns null


Wahoo... I have that fixed now. You are the one that put me onto the
solution. I did have the field in my table, but because of a typo, it
wasn't getting into my dataset.

So thanks *very much* for that! I appreciate the help.

Now my problem is that the field is a foreign key to the Categories
table. Category.pk <-->> Subcategories.fk

So there's no way I can use Subcategories.pk for the relationship.


---------
Again, let's focus in your current problem, it's not a matter of
relationship, but it's that the column is not found in the Colums
collection
of the table.


Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Ignacio Machin \( .NET/ C# MVP \)
Guest
 
Posts: n/a
#9: Nov 16 '05

re: problem: ds.Tables ["xx"].Columns ["xx"] always returns null


Hi ,
[color=blue]
> Now my problem is that the field is a foreign key to the Categories
> table. Category.pk <-->> Subcategories.fk
>
> So there's no way I can use Subcategories.pk for the relationship.[/color]

You don;t need it, just create the DataRelation between the two columns.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


Closed Thread