我是按学号查询数据库记录的啊,但是因为什么,第次显示的只是数据库内的第一行数据啊。
select * from s_info where s_no=text1.text
用这个语句用调用所有这个有关学号的信息,并在其它的文本框内显示和这个学号相对应的数据。
例如:text12.text=myrecord.fiel("s_name").value
text13.text=myrecord.fiel("s_sex").value 就是这样的语句,为什么不对啊?
select * from s_info where s_no=text1.text
用这个语句用调用所有这个有关学号的信息,并在其它的文本框内显示和这个学号相对应的数据。
例如:text12.text=myrecord.fiel("s_name").value
text13.text=myrecord.fiel("s_sex").value 就是这样的语句,为什么不对啊?
----------------------------------------
如果你的表中的s_no是唯一的,这样查到的记录当然最多只有一条
----------------------------------------
fiel写错了,是fields
myrecord.open "select * from s_info where s_no=" & trim(text1.text) ,cnn
Private myrecord As New ADODB.RecordsetPrivate Sub Form_Load()
Dim sql As Boolean
Set myconn = New ADODB.Connection
myconn.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=data_base;Data Source=jsj"
myconn.Open
Set myrecord = New ADODB.RecordsetPrivate Sub querycmd_Click()
Dim i As String
Dim strsql As String
Text1.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Text7.Text = ""
Text8.Text = ""
Text9.Text = ""
strquerysql = Empty
If (Text10.Text <> "") Then
strsql = "select * from s_info where='" & Trim(Text10.Text) & "'order by desc"
Text1.Text = myrecord.Fields("s_name").ValueElse
MsgBox "对不起!没有您检索的学号!", vbInformation + vbOKOnly, "检索警告!"
Text10.SetFocus
End IfEnd Sub
------------------------------------------------
sql语句没写对,where后面少了字段名strsql = "select * from s_info where s_no='" & Trim(Text10.Text) & "'order by desc"
If Trim(Text10.Text) <>"" Then
strsql = "select * from s_info where s_no='" & Trim(Text10.Text) & "'order by desc"
Text1.Text = myrecord.Fields("s_name").Value & ""Else
......
strsql = "select * from s_info where s_no='" & Trim(Text10.Text) & "'order by s_no desc"
Set myrecord = myconn.Execute(strsql)
If Not myrecord.EOF Then
Text1.Text = myrecord.Fields("s_name").Value
Else
MsgBox "对不起!没有您检索的学号!", vbInformation + vbOKOnly, "检索警告!"
Text10.SetFocus
End If
End If
'语句有问题 where 后面的条件没跟对。该成如下:
strsql = "select * from s_info where s_no='" & Trim(Text10.Text) & "'" 'strsql = "select * from s_info where='" & Trim(Text10.Text) & "'order by desc" '你只给strsql 这个字符串赋值了,但是没有执行这个sql语句啊,当然你每次取得都是第一条记录了
'在这里添加一条执行语句
myrecord Open strsql, myconn, adOpenStatic, adLockOptimistic
Text1.Text = myrecord.Fields("s_name").Value