我想在初始化connectionString后在SQL SErver中获取一个名为"Petro"的表的Schema,我使用此代码
conn.open();
conn.getSchema("Tables");
Run Code Online (Sandbox Code Playgroud)
但它返回所有表的模式.我只想要Petro架构.我该怎么办?
Jas*_*ira 18
string[] restrictions = new string[4];
restrictions[2] = "Petro";
DataTable table = conn.GetSchema("Tables",restrictions);
Run Code Online (Sandbox Code Playgroud)
在这里查看更多信息:MSDN:使用GetSchema方法
编辑:使用GetSchema而不是getSchema
您可以通过以下方式检索架构:
string sql = "select * from Petro WHERE 1 = 0";
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
SqlDataReader reader = cmd.ExecuteReader();
DataTable schema = reader.GetSchemaTable();
Run Code Online (Sandbox Code Playgroud)