c#知道一个表名,怎么判断这个表里边那个字段是主键,请高手解答,谢谢
需要的是代码,o(∩_∩)o...
表不是自己创建的
[解决办法]
try { SqlDataAdapter da = new SqlDataAdapter("select * from table","Data Source=127.0.0.1;Initial Catalog=db;Persist Security Info=True;User ID=sa;Password=12345;"); da.MissingSchemaAction = MissingSchemaAction.AddWithKey; DataTable dt = new DataTable(); da.Fill(dt); foreach (DataColumn col in dt.PrimaryKey) { MessageBox.Show(col.ColumnName); } } catch { MessageBox.Show("error"); } }