我的库中的表只有板有3条记录,每次运行他都会提示eof或bof一个为真,当我把
Set rs = conn.Execute("select * from stu where no ='" & txt_no.Text & "'")中txt_no.text直接改为2还是查询不出来,我的库中字段no为关键字,3条记录的no分别为1.2.3
Private Sub Form_Load()
Me.cmbminzu.AddItem "han"
Me.cmbminzu.AddItem "han"
Me.cmbzhicheng.AddItem "jiaoshou"
Me.cmbzhicheng.AddItem "gongren"
'使屏幕出来直接?示在屏幕中央
Form1.Left = (Screen.Width - Form1.Width) / 2
Form1.Top = (Screen.Height - Form1.Height) / 2
Set cmd = New Command
Set rs = New Recordset
Set conn = New Connection
'?接数据?
conn.ConnectionString = "DSN=kk;uid=;pwd="
Dim year As Integer
conn.Open
Set cmd.ActiveConnection = conn
Set rs = conn.Execute("select * from stu where no ='" & txt_no.Text & "'")
txt_no.Text = rs.Fields("no")
txt_name.Text = rs.Fields("name")
year = Format(Now, "yyyy")
txt_brithday.Text = year - Format(rs.Fields("brithday"), "yyyy")
txt_pay.Text = rs.Fields("pay")
Me.cmbzhicheng.Text = rs.Fields("zhicheng")
Me.cmbminzu.Text = rs.Fields("minzu")
rs.Close
conn.Close
End Sub
Set rs = conn.Execute("select * from stu where no ='" & txt_no.Text & "'")中txt_no.text直接改为2还是查询不出来,我的库中字段no为关键字,3条记录的no分别为1.2.3
Private Sub Form_Load()
Me.cmbminzu.AddItem "han"
Me.cmbminzu.AddItem "han"
Me.cmbzhicheng.AddItem "jiaoshou"
Me.cmbzhicheng.AddItem "gongren"
'使屏幕出来直接?示在屏幕中央
Form1.Left = (Screen.Width - Form1.Width) / 2
Form1.Top = (Screen.Height - Form1.Height) / 2
Set cmd = New Command
Set rs = New Recordset
Set conn = New Connection
'?接数据?
conn.ConnectionString = "DSN=kk;uid=;pwd="
Dim year As Integer
conn.Open
Set cmd.ActiveConnection = conn
Set rs = conn.Execute("select * from stu where no ='" & txt_no.Text & "'")
txt_no.Text = rs.Fields("no")
txt_name.Text = rs.Fields("name")
year = Format(Now, "yyyy")
txt_brithday.Text = year - Format(rs.Fields("brithday"), "yyyy")
txt_pay.Text = rs.Fields("pay")
Me.cmbzhicheng.Text = rs.Fields("zhicheng")
Me.cmbminzu.Text = rs.Fields("minzu")
rs.Close
conn.Close
End Sub
请确认no字段是否是字符型的,如果不是就用:
select * from stu where no =" & txt_no.Text
select * from stu where no =int(" & txt_no.Text &")
Set rs = conn.Execute("select * from stu where no ='" & txt_no.Text & "'")
他总是抱eof或bof有一个为真的错啊 !
The Recordset is empty
end if
select * from stu where stu.no='" & trim(txt_no.text) & "'"
看看这个贴子就知道了
txt_name.Text = rs.Fields("name")
name是库中的一个字段,这样都查询不出来,还是抱eof or bof出错!还有,我在库中的no就是字符形~!还忘大家帮忙,我也知道是没有符合的记录,但是判断怎么加?
在数据库窗体中左边树有一个“查询”项,选它。点“在设计视图中创建查询”,然后加入你的表,在窗体上右击点“SQL视图”,在那里写
EOF,是指数据库的记录指针已经达到了最后一个记录的后面,也就是说数据集为空啦
BOF, 是指数据库的记录指针处在了第一个记录的前面 很明显,你的查询语句没有查找到满足条件的记录,你可以作一个判断,不满足的时候执行什么(比如提示没有找到,相应的文本框清空等等),满足的时候再给相应的文本框赋值。
Set cmd.ActiveConnection = conn
Set rs = conn.Execute("select * from stu where no ='" & txt_no.Text & "'")
if rs.eof or rs.bof then txt_no = ""
txt_name = ""
txt_brithday = ""
txt_pay = ""
cmbzhicheng.text = ""
cmbminzu.text = ""
else txt_no = rs.Fields("no")
txt_name = rs.Fields("name")
year = Format(Now, "yyyy")
txt_brithday = datediff("yyyy",now,rs.Fields("brithday"))
txt_pay = rs.Fields("pay")
cmbzhicheng.Text = rs.Fields("zhicheng")
cmbminzu.Text = rs.Fields("minzu")
end ifrs.Close
conn.Close
再次感谢,还有一个问题,可以推荐一个地址让我学习水晶报表的地方吗?以前我从来都没有接触过水晶报表,现在要用到!!!!!