读书人

c#如何获取access的主键字段

发布时间: 2012-01-08 22:48:50 作者: rapoo

c#怎么获取access的主键字段
哪位知道,请帮帮我,有急用!

[解决办法]
access没有自动增长列,你在程序插入的时候就判断最大值后加一
不要重复,这个字段就成主键值了
[解决办法]
try:

OleDbConnection cnn = new ...;
OleDbDataAdapter da = new ....( "select * from table1 ",cnn);
da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
DataTable dt = new ...
da.Fill(dt);
//通过PrimaryKey属性取主键
Response.Write(dt.PrimaryKey[0].ColumnName);

读书人网 >asp.net

热点推荐