请问,在读取数据源时,如何实现只读取符合设定条件的记录的目的?
本帖最后由 作者 于 2009-12-24 19:02:30 编辑 <br /><br /> <p class="MsoNormal" style="MARGIN: 0mm 0mm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0;">之前通过以下语句与作为数据源的工作簿<font face="Times New Roman">x</font>建立连接,并读取工作簿<font face="Times New Roman">x</font>中的工作表<font face="Times New Roman">y</font>的数据到<font face="Times New Roman">MSHFlexGrid</font>中:</p><p class="MsoNormal" style="MARGIN: 0mm 0mm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0;"><font face="Times New Roman">adoCnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & "Persist Security Info=False;" & _<p></p></font></p><p></p><p></p><p class="MsoNormal" style="MARGIN: 0mm 0mm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0;"><font face="Times New Roman"><span style="mso-spacerun: yes;"> "Data Source=" & APP_PATH & "</font></span>工作簿<font face="Times New Roman">x;" & _<p></p></font></p><p></p><p></p><p class="MsoNormal" style="MARGIN: 0mm 0mm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0;"><font face="Times New Roman"><span style="mso-spacerun: yes;"> "Extended Properties='Excel 8.0;HDR=Yes'"<p></p></font></span></p><p></p><p></p><p class="MsoNormal" style="MARGIN: 0mm 0mm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0;"><font face="Times New Roman"><span style="mso-spacerun: yes;"> <p></p></font></span></p><p></p><p></p><p class="MsoNormal" style="MARGIN: 0mm 0mm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0;"><font face="Times New Roman">adoRst.Open "Select<span style="mso-spacerun: yes;"> * From [</font></span>工作表<font face="Times New Roman">y$]", adoCnn, adOpenKeyset, adLockOptimistic</font></p><p class="MsoNormal" style="MARGIN: 0mm 0mm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0;"><p><font face="Times New Roman"> </font></p></p><p><font face="Times New Roman"> </font></p><p></p><p class="MsoNormal" style="MARGIN: 0mm 0mm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0;">但请问,如何修改,才可实现只读取工作表<font face="Times New Roman">y</font>中的某一字段中的内容符合条件的记录,而不是整个工作表<font face="Times New Roman">y</font>中的所有数据?</p><p class="MsoNormal" style="MARGIN: 0mm 0mm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0;">如下面的数据是工作表<font face="Times New Roman">y</font>中的内容:</p><p class="MsoNormal" style="MARGIN: 0mm 0mm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0;">序号<span style="mso-spacerun: yes;"><font face="Times New Roman"> </font></span>产地<span style="mso-spacerun: yes;"><font face="Times New Roman"> </font></span>产品</p><p class="MsoNormal" style="MARGIN: 0mm 0mm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0;"><font face="Times New Roman">1<span style="mso-spacerun: yes;"> </font></span>广东<span style="mso-spacerun: yes;"><font face="Times New Roman"> </font></span>香蕉</p><p class="MsoNormal" style="MARGIN: 0mm 0mm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0;"><font face="Times New Roman">2<span style="mso-spacerun: yes;"> </font></span>广东<font face="Times New Roman"><span style="mso-spacerun: yes;"> </font></span>苹果</p><p class="MsoNormal" style="MARGIN: 0mm 0mm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0;"><font face="Times New Roman">3<span style="mso-spacerun: yes;"> </font></span>广西<font face="Times New Roman"><span style="mso-spacerun: yes;"> </font></span>香蕉</p><p class="MsoNormal" style="MARGIN: 0mm 0mm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0;"><font face="Times New Roman">4<span style="mso-spacerun: yes;"> </font></span>安徽<span style="mso-spacerun: yes;"><font face="Times New Roman"> </font></span>梨</p><p class="MsoNormal" style="MARGIN: 0mm 0mm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0;"><font face="Times New Roman">5<span style="mso-spacerun: yes;"> </font></span>安徽<span style="mso-spacerun: yes;"><font face="Times New Roman"> </font></span>桔子</p><p class="MsoNormal" style="MARGIN: 0mm 0mm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0;">在这个例子中,如何修改上面的语句,实现:只读取“产地”字段中内容<font face="Times New Roman">=</font>“安徽”的记录的各字段内容到<font face="Times New Roman">MSHFlexGrid</font>中?</p><p class="MsoNormal" style="MARGIN: 0mm 0mm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0;"><p><font face="Times New Roman"> </font></p></p><p><font face="Times New Roman"> </font></p><p></p> <strong>请问,在读取数据源时,如何实现只读取符合设定条件的记录的目的?</strong> <font face="Times New Roman">Select * From [</font>工作表<font face="Times New Roman">y$] WHERE </font><font face="宋体">产地="安徽"</font> 非常感谢!
页:
[1]