我有视图vwGetData,它从两个表t1,t获取数据并据并有字段: " R/ s5 }+ i3 Y' \, Dt1.Field1 [ALIAS1],t1.Field2,t2.Field3,t2.Field4,t2.Field5 [ALIAS5]我将在下面提供输入+ H# D3 c. q. H7 V2 |
Select * from vwGetData我想在C#/ SQL获得以下输出 5 p! N) `2 b% g YALIAS1Field2Field3Field4ALIAS5or : q% N8 L/ h& U7 Y. S: Z' yALIAS1,Field2,Field3,Field4,ALIAS5我想使用C#和SQL这样做。 0 }4 D4 q t8 v) {. ], ~7 a 4 Q- M. y; V$ N# L, ~/ p解决方案: 3 E4 T' k: R! Q/ \: C8 ?. {
首先要做的是确保没有数据返回:; T5 Y' m& ]# R
SELECT TOP 0 [vwGetData].* FROM [vwGetData] WHERE 1 = 2;假设你现在知道如何设置一个DataReader,您将执行以下操作: 8 X5 Q# [& {0 S V- fusing(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) q4 M9 }' [; T7 {4 y
Views.