希望对你有用,建议多看看SQL方面的书籍
<p>Dim wr As Workspace '声明工作空间变量,为打开数据库提供空间<br/>Dim db As Database '声明数据库对象变更,用于打开数据库<br/>Dim dl As Recordset '声明数据库表,用于打开数据库库表<br/>Dim DTYPE As String<br/>Dim DLOAD As String<br/>Dim DSPEED As String<br/>Dim DNBE As String<br/>Dim DNBS As String<br/>Dim DRMax As String<br/>Dim strSql As String<br/>Dim rs As Recordset<br/>Dim cou As Integer, i As Integer</p><p>'以下使用DAO<br/>Set wr = CreateWorkspace("", "admin", "", dbUseJet)<br/>Set db = wr.OpenDatabase("C:\Program Files\Database.mdb", False, True, "")<br/>Set dl = db.OpenRecordset("Data", dbOpenDynaset, dbReadOnly)</p><p>strSql = "select * from GVF-II where type='" & DTYPE & _<br/> "' and load='" & DLOAD & "' and speed='" & DSPEED & _<br/> "' and nbe='" & DNBE & "' and nbstopmax='" & DNBS & _<br/> "' and rmax='" & DRMax & "'"<br/>Set rs = db.OpenRecordset(strSql, dbOpenDynaset)<br/>'如果根据此六个条件查得记录最多只有1条时,可使用以下代码<br/>If rs.RecordCount > 0 Then<br/> Debug.Print rs.Fields("type")<br/> Debug.Print rs.Fields("load")<br/> Debug.Print rs.Fields("speed")<br/> Debug.Print rs.Fields("nbe")<br/> Debug.Print rs.Fields("nbstopmax")<br/> Debug.Print rs.Fields("rmax")<br/> '也可将值赋给控件,如:TextBox1.Text=rs.Fields("type")<br/>End If<br/>'如果根据此六个条件查得记录可能有2条以上时,可使用以下代码<br/>If Not rs.EOF Then<br/> rs.MoveLast<br/> cou = rs.RecordCount<br/> rs.MoveFirst<br/>Else<br/> cou = rs.RecordCount<br/> rs.MoveFirst<br/>End If</p><p>For i = 1 To cou<br/> Debug.Print rs.Fields("type")<br/> Debug.Print rs.Fields("load")<br/> Debug.Print rs.Fields("speed")<br/> Debug.Print rs.Fields("nbe")<br/> Debug.Print rs.Fields("nbstopmax")<br/> Debug.Print rs.Fields("rmax")<br/> rs.MoveNext<br/>Next i</p> <p><strong><font face="Verdana" color="#61b713">jxh2003zfr,谢谢你的帮助!</font></strong></p><p><font face="Verdana" color="#61b713"><strong>但是我研究了好久,程序总是在“</strong><font color="#000000">Set rs = db.OpenRecordset(strSql, dbOpenDynaset)</font><br/>”这里停住,并且提示“FROM 子句语法错误”。</font></p><p><font face="Verdana" color="#61b713">因为我对SQL不懂,然后自己调了半天,依旧是这样。还望赐教!</font></p><p><font face="Verdana" color="#61b713">谢谢!!</font></p>问题解决了吗
idoo发表于2007-10-6 22:26:00static/image/common/back.gifjxh2003zfr,谢谢你的帮助!但是我研究了好久,程序总是在“Set rs = db.OpenRecordset(strSql, dbOpenDynaset)”这里停住,并且提示“FROM 子句语法错误”。因为我对SQL不懂,然后自己调了半天<p>呵呵,问题解决了吗,如果还没解决的话请发你的sql语句上来看看。</p>
页:
1
[2]