0
我想獲取特定表的模式,但我列爲空。沒有獲得特定表的列
我試圖讓導致這下面類:
public class Tables
{
public string Name { get; set; }
public string[] Columns { get; set; }
}
代碼:
string[] selectedTables = { "Table1", "Table2"};
var conectionString = new SqlConnection("MyconnectionString");
var data = new List<Tables>();
data = conectionString.GetSchema("Tables").AsEnumerable()
.Select
(
t => new Tables
{
Name = t[2].ToString(),
Columns = conn.GetSchema("Columns",
new string[] { databaseName,t[2].ToString() }).AsEnumerable() // t[2].ToString() represent tablename
.Where(c => selectedTables.Contains(t[2].ToString()))
.Select(c => c[3].ToString()).ToArray() // c[3].ToString() represent Columns
}).ToList();
return data;
雖然在數據我收到表的列表,即Table0,Table1,Table2,Table3
等。但我沒有得到這個Table1 and Table2
選定的表的列。
更新:我正在尋找這樣的事情:
// You can specify the Catalog, Schema, Table Name, Table Type to get
// the specified table(s).
// You can use four restrictions for Table, so you should create a 4 members array.
String[] tableRestrictions = new String[4];
// For the array, 0-member represents Catalog; 1-member represents Schema;
// 2-member represents Table Name; 3-member represents Table Type.
// Now we specify the Table Name of the table what we want to get schema information.
tableRestrictions[2] = "Course";
DataTable courseTableSchemaTable = conn.GetSchema("Tables", tableRestrictions);
data = conectionString.GetSchema("Tables").AsEnumerable()
.Select
(
t => new Tables
{
Name = t[2].ToString(),
Columns = (from useTable in selectedTables
let columns = conn.GetSchema("Columns",new string[] { databaseName, t["TABLE_SCHEMA"].ToString(), useTable })
select new { columns[3]}) //Error
}).ToList();
如何注入我selectedTables?
這是很多工作fine.Thanks您對^ h樣的努力給我打電話,請繼續幫助像這樣:) –