laoxie_198 发表于 2006-8-17 17:18:00

求高手指点

<P>这是我的一个读取sql里数据的vb,库里有很多条记录的,我怎么只能读出其中的第一条记录呀?高手们帮我看看吧!<BR>Private Sub hb_Click()<BR>Dim ysjlj As New ADODB.Connection<BR>Dim ygg01 As New ADODB.Recordset<BR>Dim xsjlj As New ADODB.Connection<BR>Dim xgg01 As New ADODB.Recordset<BR>Dim ygg1, xgg1 As String<BR>Dim yljzfc, xljzfc, ysj, xsj As String '源新数据库连接字符串</P>
<P>yljzfc = "provider=sqloledb.1;password=" &amp; yyhmm.Text &amp; ";persist security info=true;user id=" &amp; yyhm.Text &amp; ";initial catalog=" &amp; ysjk.Text &amp; " ;data source=" &amp; yfwq.Text &amp; ""<BR>ysjlj.Open yljzfc '连接源数据库</P>
<P>xljzfc = "provider=sqloledb.1;password=" &amp; xyhmm.Text &amp; ";persist security info=true;user id=" &amp; xyhm.Text &amp; ";initial catalog=" &amp; xsjk.Text &amp; " ;data source=" &amp; xfwq.Text &amp; ""<BR>xsjlj.Open xljzfc '连接源数据库<BR>'xsj = " select * into gg1 from gg01 where ga01='1'"<BR>'xgg01.Open xsj, xsjlj, adOpenKeyset, adLockPessimistic '在新数据库中新建gg1表<BR>'xgg01.Close<BR>'下面将源数据库中gg01表的内容导入到gg1表中。<BR>ysj = "select *from gg01 where ga033='114'"<BR>ygg01.Open ysj, ysjlj, adOpenKeyset, adLockPessimistic</P>
<P>xsj = "select * from gg1"<BR>xgg01.Open xsj, xsjlj, adOpenKeyset, adLockPessimistic<BR>i = 0<BR>If Not ygg01.EOF Then<BR>i = i + 1<BR>&nbsp;xgg01.AddNew<BR>&nbsp;xgg01.Fields("ga01") = ygg01.Fields("ga01")<BR>&nbsp;xgg01.Fields("ga18") = ygg01.Fields("ga18")<BR>&nbsp;xgg01.Fields("ga03") = ygg01.Fields("ga03")<BR>&nbsp;xgg01.Fields("ga04") = ygg01.Fields("ga04")<BR>'xgg01.Update<BR>&nbsp;'Print ygg01.Fields("ga18")<BR>&nbsp;ygg01.MoveNext<BR>&nbsp;xgg01.MoveNext<BR>&nbsp;<BR>Else<BR>&nbsp;'ygg01.Close<BR>&nbsp;'xgg01.Close<BR>&nbsp; 'Exit Sub<BR>End If<BR>&nbsp;<BR>&nbsp;Print i</P>
<P>;我的i值怎么都是1,可是我的库里有很多行的.</P>

wyj7485 发表于 2006-8-17 18:23:00

<P>Do While Not ygg01.EOF </P>
<P>..........</P>
<P>Loop</P>
页: [1]
查看完整版本: 求高手指点