这是我第一次尝试SQL查询。我在下面的查询效果很好,但是如何将结果输入VBA变量以便我可以使用它们?
Dim mSQL As String = "select AD_ADDR1, AD_ADDR2, PR_SALEPR1, SC_SOURCE1, SC_SOURCE2, FN_CONC1,FN_CONC2, DT_SALTIM1, LC_LOCAT1, RG_RIGHTS, ST_SITSIZE, ST_SITEVW,DA_DESAPL1, DA_CONSTQL, AG_AGYRBLT, AG_COND1, RM_TOTAL, RM_BED,RM_BATH, SF_GLA, BM_BSM1, BM_BSM2, FU_FUNCTUT, HC_HTCOOL, EE_EFFIC1,CR_GARPRK1, PF_PORPAT1, BL_BLANK1, BL_BLANK2, BL_BLANK3, HS_PRIOR1, HS_PRIOR2, HS_PRIOR3, HS_DSDATE from TOTALFormSource"
Dim dt As DataTable = Nothing
Dim ds As New DataSet
Try
Using con As New SQLiteConnection(connectionString)
Using cmd As New SQLiteCommand(mSQL, con)
con.Open()
Using da As New SQLiteDataAdapter(cmd)
da.Fill(ds)
dt = ds.Tables(0)
End Using
End Using
End Using
答案 0 :(得分:0)
这可能会给你一个想法。它可能无法编译(我现在正在安装软件,因此无法使用VS):
Dim mSQL As String = "select AD_ADDR1, AD_ADDR2, PR_SALEPR1, SC_SOURCE1, SC_SOURCE2, FN_CONC1,FN_CONC2, DT_SALTIM1, LC_LOCAT1, RG_RIGHTS, ST_SITSIZE, ST_SITEVW,DA_DESAPL1, DA_CONSTQL, AG_AGYRBLT, AG_COND1, RM_TOTAL, RM_BED,RM_BATH, SF_GLA, BM_BSM1, BM_BSM2, FU_FUNCTUT, HC_HTCOOL, EE_EFFIC1,CR_GARPRK1, PF_PORPAT1, BL_BLANK1, BL_BLANK2, BL_BLANK3, HS_PRIOR1, HS_PRIOR2, HS_PRIOR3, HS_DSDATE from TOTALFormSource"
Dim dt As DataTable
Dim ds As New DataSet
Using con As New SQLiteConnection(connectionString)
Using cmd As New SQLiteCommand(mSQL, con)
con.Open()
Using da As New SQLiteDataAdapter(cmd)
da.Fill(ds)
dt = ds.Tables(0)
End Using
End Using
End Using
For Each dr As DataRow In dt.Rows
' You can now access dr("AD_ADDR1"), etc.
Next
请注意,我摆脱了= Nothing
。你不需要它。您也没有向我们展示Catch
中的内容,因此我摆脱了Try
。