您要做的第一件事是确保没有数据被返回:
SELECT TOP 0 [vwGetData].* FROM [vwGetData] WHERE 1 = 2;
现在假设您知道如何设置一个DataReader,您将执行以下操作:
using(var reader = command.ExecuteReader())
{
// This will return false - we don't care, we just want to make sure the schema table is there.
reader.Read();
var tableSchema = reader.GetSchemaTable();
// Each row in the table schema describes a column
foreach (DaTarow row in tableSchema.Rows)
{
Console.WriteLine(row["ColumnName"]);
}
}
您也可以查看SQL Catalog SYS视图。