这是我做的简单查询(是用字符串连接的):
Dim SQL As String
Dim Conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim connect As String
If Text1.Text <> "" Then
DataGrid1.Caption = "姓名查询信息"
connect = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=student;Data Source=C1C19FA2F49841C"
Set Conn = New ADODB.Connection
Conn.Open connect
SQL = "select *from students where s_name = '" + Trim(Text1.Text) + "'"
Set rs = New ADODB.Recordset
rs.Open SQL, Conn, adOpenStatic
Set DataGrid1.DataSource = rs