我有视图vwGetData,它从两个表t1,t获取数据并据并有字段: % z( {4 A0 [" p8 yt1.Field1 [ALIAS1],t1.Field2,t2.Field3,t2.Field4,t2.Field5 [ALIAS5]我将在下面提供输入 4 p6 E$ u3 ^ k8 w2 dSelect * from vwGetData我想在C#/ SQL获得以下输出8 W4 k& X; o( [
ALIAS1Field2Field3Field4ALIAS5or8 w! |6 F9 \* k/ y
ALIAS1,Field2,Field3,Field4,ALIAS5我想使用C#和SQL这样做。2 d- Y( k7 K1 Q& i2 Y8 W
' z. K# l+ M- `. P" |+ k" ~8 ? 解决方案: - \" |# S/ n9 X" l1 f 首先要做的是确保没有数据返回: # D9 y0 S. H! }8 i$ k x ^ QSELECT TOP 0 [vwGetData].* FROM [vwGetData] WHERE 1 = 2;假设你现在知道如何设置一个DataReader,您将执行以下操作: + a& ?0 Q; H0 @0 wusing(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"]); }}You can also could also look into the SQL Catalog SYS 0 n! x: d- p7 }Views.