日期:2014-05-18 浏览次数:21031 次
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"); } }