OleDbDataAdapter.Fill doesnt fill primary keys into DataTable  
Author Message
Maartin





PostPosted: .NET Framework Data Access and Storage, OleDbDataAdapter.Fill doesnt fill primary keys into DataTable Top

Hi,
m_dbAdptrRemedies = new OleDbDataAdapter("",
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + m_RemediesFilename);

m_dbAdptrRemedies.SelectCommand.CommandText =
"SELECT Nr, Name, Bezug, [Position], * FROM tListenListe ORDER BY [Position]";
table = new DataTable();
m_dbAdptrRemedies.Fill(table);

Although Ive set a primary key for column "Nr" in MS Access the filled DataTable has no primary key set.
Sure I could do it myself, but I want to find out if the SELECT command returns data with our without primary key, because there might be wrong tables that dont have it and this way wont allow to use a CommandBuilder for update lateron.
(BTW: is it possible to make an existin column a primary key in .net and save it back to the database So far I always used MS Access to do this)



.NET Development30  
 
 
DMan1





PostPosted: .NET Framework Data Access and Storage, OleDbDataAdapter.Fill doesnt fill primary keys into DataTable Top

You must setup the table either progmatically or using a wizard to have the correct column datatypes and constraints:

Table.Constraints.Add("ContraintName", Columns(), PrimaryKey)

http://msdn2.microsoft.com/en-us/library/system.data.datatable.constraints.aspx



 
 
Paul Domag





PostPosted: .NET Framework Data Access and Storage, OleDbDataAdapter.Fill doesnt fill primary keys into DataTable Top

(BTW: is it possible to make an existin column a primary key in .net and save it back to the database So far I always used MS Access to do this)

Hi,

Sorry this is not possible. You cannot edit the table's schema by using ADO.Net except if you send ALTER commands to your table. You can use the ADOX component to achieve this.

ALTER Table

http://msdn.microsoft.com/library/default.asp url=/library/en-us/tsqlref/ts_aa-az_3ied.asp

ADOX component

http://msdn.microsoft.com/library/default.asp url=/library/en-us/ado270/htm/admscadoxfundamentals.asp

cheers,

Paul June A. Domag



 
 
Bill Lin - MSFT





PostPosted: .NET Framework Data Access and Storage, OleDbDataAdapter.Fill doesnt fill primary keys into DataTable Top

You could use Adapter.FillSchema() to retrieve the primary key informaiton. Alternatively, you can set Adapter.DataAdapter.MissingSchemaAction to AddWithKey.

 
 
Maartin





PostPosted: .NET Framework Data Access and Storage, OleDbDataAdapter.Fill doesnt fill primary keys into DataTable Top

Thx, for your great help!