我想要使用ADO.Net獲取表的所有關係。下面我有下面的代碼,但我無法得到Data.Relations或DataSet.Tables [0] .ChildRelations/ParentRelations使用c#獲取Sql表關係
string query = string.Format("SELECT TOP 0 * FROM {0}", tableName);
var ds = new DataSet(tableName);
SqlCommand sqlCmd = new SqlCommand(query, connection);
SqlDataAdapter sda = new SqlDataAdapter(sqlCmd);
sda.FillSchema(ds, SchemaType.Source, tableName);
sda.Fill(ds, tableName);
sda.Dispose();
謝謝!
你可以使用Microsoft.SqlServer.Management.Smo命名空間 – 1Mayur
我遇到過這個解決方案,但不想實現它,因爲我很快就想支持OLEDB連接等等。 – harsimranb