选择除特定列以外的所有列

时间:2014-01-02 04:34:45

标签: vb.net ms-access

我在我的表中使用asp.net和msaccess2003以及30到40列,我想要选择所有列,但除了特定列之外,不需要我在程序执行时知道的列

2 个答案:

答案 0 :(得分:2)

在VB.NET中,使用一条记录加载DataTable。然后,您可以构建一个列的列,不包括您要排除的列。

Dim tblTemp As DataTable
Dim SQL As String = "SELECT TOP 1 * FROM MyTable"
'Fill tblTemp from the above sql 

' generate a columns list string excluding the Blah column
Dim L As Integer
Dim columns As String
For L = 0 To tblTemp.Columns.Count - 1
    If tblTemp.Columns(L).ColumnName <> "Blah" Then
        If columns <> "" Then columns &= ", "
        columns &= tblTemp.Columns(L).ColumnName
    End If
Next

Dim FinalSQL As String
FinalSQL = "SELECT " & columns & " FROM MyTable"

答案 1 :(得分:1)

/* Get the data into a temp table */
SELECT * INTO #TempTable
FROM YourTable

/* Drop the cloumns that are not needed */
ALTER TABLE #TempTable
DROP COLUMN ColumnToDrop

  // Get results and drop temp table 
SELECT * FROM #TempTable
DROP TABLE #TempTable

希望这有帮助