fillschema doesnt set pk info

U

user100

Need help please.

I'm filling a table with the data from a database. Everything is fine,
except after calling FillSchema, PrimaryKey property of the table[0]
remains empty, never gets set. I tried everything.

BTW, FillSchema does set column information, such as AllowDBNull,
etc..It just Primary Keys string that never gets set.
Please help.

Fill works all right too.

Table I'm working with has 1 primary key.

Here is my code:
****************************************************
OleDbCommand cm = new OleDbCommand("SELECT * FROM " + tableName,
conn);
DataSet ds = new DataSet();
OleDbDataAdapter da = new OleDbDataAdapter();
da.SelectCommand = cm;

//Add constraints and pkeys
//da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
da.FillSchema (ds, SchemaType.Mapped);
DataTable dt = ds.Tables[0];
//Add rows
da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
da.Fill(dt);
****************************************************

user100
 
T

Thomas W. Brown

-----Original Message-----
Need help please.

I'm filling a table with the data from a database. Everything is fine,
except after calling FillSchema, PrimaryKey property of the table[0]
remains empty, never gets set. I tried everything.

BTW, FillSchema does set column information, such as AllowDBNull,
etc..It just Primary Keys string that never gets set.
Please help.

Fill works all right too.

Table I'm working with has 1 primary key.

Here is my code:
****************************************************
OleDbCommand cm = new OleDbCommand("SELECT * FROM " + tableName,
conn);
DataSet ds = new DataSet();
OleDbDataAdapter da = new OleDbDataAdapter();
da.SelectCommand = cm;

//Add constraints and pkeys
//da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
da.FillSchema (ds, SchemaType.Mapped);
DataTable dt = ds.Tables[0];
//Add rows
da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
da.Fill(dt);
****************************************************

user100
.

I wonder if it's because you're using SchemaType.Mapped
instead of SchemaType.Source?

All I know for sure is that I'm using the SqlClient stuff
I can use DataAdapter.FillSchema and obtain primary key
information in addition to everything else. But I am
specifying "source" for my schema type.

Perhaps it's a limitation of the OleDb objects, that they
can't get pk information from the database??

-- TB
 
U

user100 a

maybe you're right, because setting it to source doesn't
work either.

I even tried doing it with reader, thinking that maybe
i could get it thru schema table. something like that:
OleDbDataReader dr;
dr = cm.ExecuteReader(CommandBehavior.KeyInfo);
DataTable tst = dr.GetSchemaTable();

but i got same thing, no constraint information. *sigh*

Thanks for reply, anyway, Thomas.

user100
 
D

David Sceppa

What OLE DB provider are you using? It's possible that the
provider doesn't return this schema information.

David Sceppa
Microsoft
This posting is provided "AS IS" with no warranties,
and confers no rights. You assume all risk for your use.
© 2003 Microsoft Corporation. All rights reserved.
 
U

user100

I think you are correct, i tried to do it with .net data provider for
oracle(oracle client) and it works. So maybe thats waht i should do.
(before I was using .net oledb provider).

Thanks for all your help.
 

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