查询结果
我做了一个查询,这个SQL语句由用户自己根据自己的需要输入到一个text控件中,然后点击按钮执行查询过程,结果在datagrid中显示。这些都已实现。现在我想问的问题是:当输入如select * from table句时,这个table的最后两个field内容不在datagrid中显示,不知如何做?可以设置datagrid吗?
当然不能用select field1,field2,...fieldn from table 来实现。因为用户是不会记住那么多field name. 谢谢!
Private Sub CmdExecute_Click()
On Error GoTo Err_Execute
Dim strSql As String
Dim rstSql As New ADODB.Recordset
If Trim(TxtSQL.Text) = "" Then
MsgBox "SQL text is blank. Please check!", vbOKOnly, "Prompt"
Exit Sub
End If
rstSql.CursorLocation = adUseClient
'strSql = "select * from pc"
strSql = Trim(TxtSQL.Text)
strSql = LCase(strSql)
If InStr(1, strSql, "update") <> 0 Or InStr(1, strSql, "delete") <> 0 _
Or InStr(1, strSql, "create") <> 0 Or InStr(1, strSql, "alter") <> 0 Or InStr(1, strSql, "drop") <> 0 Then
MsgBox "The action is danger! Can not be executed!", vbOKOnly + vbExclamation, "Warning"
Exit Sub
End If
rstSql.Open strSql, cnn, adOpenKeyset, adLockPessimistic
Set DgdExplorer.DataSource = rstSql
DgdExplorer.Refresh
Set rstSql = Nothing
Exit Sub
Err_Execute:
MsgBox "SQL syntax error! Please check!", vbOKOnly + vbExclamation, "Warning"
Exit Sub
End Sub