开发者

How to create primary key on DBF table?

I am using the OLEDB driver (Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extend开发者_如何学Pythoned Properties=dBase IV) to work with a DBF table. I am running into an issue when I attempt to create a primary key on an existing column. I have been through several variations of syntax with no success.

What is the correct syntax for creating a primary key using OLEDB against a DBF table?


Try this:

using (OleDbConnection cn = new OleDbConnection("Provider=Microsoft.Jet..."))
using (OleDbCommand cmd = new OleDbCommand("ALTER TABLE MyTable ADD CONSTRAINT idxMyTable PRIMARY KEY (MyColumn)", cn))
{
  cn.Open();
  cmd.ExecuteNonQuery();
}

Of course, you have to make sure the index doesn't already exist nor the values in the column do not currently violate the proposed primary key, etc.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜