getSchema() 获得表主键问题

ZhuoCh117 2009-04-01 10:24:57
为什么得不到主键啊 数据库表user_if_t 确实有主键的

会是什么情况原因? 请高手指点下~~~ 谢谢

 static void Main()
{
string connectionString = GetConnectionString();
using (SqlConnection connection =
new SqlConnection(connectionString))
{
//Connect to the database, and then retrieve the
//schema information.
connection.Open();
string[] restrictions = new string[4];
restrictions[1] = "dbo";
restrictions[2] = "user_if_t";

DataTable table = connection.GetSchema("Tables", restrictions);

GetPrimaryKeys(table);
// Console.WriteLine(table.Constraints.GetEnumerator);
Console.WriteLine("Press any key to continue.");
Console.ReadKey();
}
}

private static string GetConnectionString()
{
// To avoid storing the connection string in your code,
// you can retrieve it from a configuration file.
return "Data Source=ISS-GHOST\\SQL2008;Initial Catalog=bond2;Integrated Security=True";
}

private static void GetPrimaryKeys(DataTable table)
{
// Create the array for the columns.
DataColumn[] columns;
columns = table.PrimaryKey;

// Get the number of elements in the array.
Console.WriteLine("PK Count: " + columns.Length);
for (int i = 0; i < columns.Length; i++)
{
Console.WriteLine(columns[i].ColumnName + columns[i].DataType);
}
}
...全文
270 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
keyword123 2009-04-17
  • 打赏
  • 举报
回复
ZhuoCh117 2009-04-01
  • 打赏
  • 举报
回复
没有人会吗?? 伤心……

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧