简体   繁体   中英

I Want to know the exact datatype(dbtype) of the ms access database table column in c#

need to know the exact info of database and containing tables using c#. database is MS access.i want to full info of the tables in it like primary key,max length,not null of the columns in tables in ms access database,etc.. so whats the best way of doing it....

advanced thanx for any kind of help.

another issue is getschema gives me datatypes in numeric way like 130,131.. so how can i use them in create table query they give error

let me explain what i am trying to do.i want to recreate the database about which i have no information.i don't know about its size,tables,data or any thing. actually i have succeeded to an extent.what i have done is i get the db name and create it with CatalogClass and with getschema(tables) i get all the table names and create them with create table from C#.then column names with alter table.and now i have to give it constraints which are in the DB which have been provided. so,other then this method i have used is there any thing else which i am missing.any easy or better way available to do this.so, it can go faster

question is still open

I believe everything is documented at the link below, try to run it step by step with debug and then u can inspect the element and display every value you want.

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

Primary Key: DataTable.PrimaryKey Max Length, of what? Records? DataTable.Rows.Count Columns? DataTable.Columns.Rows

It appears that you are using a schema to return the field types. I have been testing, and something on these lines appears to return what you want.

ADODB.Connection cn = new ADODB.Connection();
ADODB.Recordset rs = new ADODB.Recordset();
string cnStr;

cnStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Z:\\Docs\\Test.accdb";
string ssql = "Select * From Table1 where 1=2";

cn.Open(cnStr, null, null, 0);

rs.Open(ssql, cn, ADODB.CursorTypeEnum.adOpenKeyset, 
    ADODB.LockTypeEnum.adLockOptimistic, -1);

foreach (ADODB.Field fld in rs.Fields)
{
    Console.WriteLine(fld.Type);
}
Console.Read();

rs.Close();
cn.Close();

For various types this returns:

adInteger
adVarWChar = Text
adDate
adInteger
adLongVarWChar = Memo
adVarWChar
adDate
adBoolean

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM