我是按学号查询数据库记录的啊,但是因为什么,第次显示的只是数据库内的第一行数据啊。
select * from s_info where s_no=text1.text
用这个语句用调用所有这个有关学号的信息,并在其它的文本框内显示和这个学号相对应的数据。
例如:text12.text=myrecord.fiel("s_name").value
      text13.text=myrecord.fiel("s_sex").value 就是这样的语句,为什么不对啊?

解决方案 »

  1.   

    select * from s_info where s_no=text1.text
    ----------------------------------------
    如果你的表中的s_no是唯一的,这样查到的记录当然最多只有一条
      

  2.   

    text12.text=myrecord.fiel("s_name").value
    ----------------------------------------
    fiel写错了,是fields
      

  3.   

    myrecord.open "select * from s_info where s_no='" & trim(text1.text) & "'",cnn如果学号是数字型:
    myrecord.open "select * from s_info where s_no=" & trim(text1.text) ,cnn
      

  4.   

    Private myconn As New ADODB.Connection
    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
      

  5.   

    strsql = "select * from s_info where='" & Trim(Text10.Text) & "'order by desc"
    ------------------------------------------------
    sql语句没写对,where后面少了字段名strsql = "select * from s_info where s_no='" & Trim(Text10.Text) & "'order by desc"
      

  6.   

    ......
    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
    ......
      

  7.   

    还是那样啊,每次查到的是第一条记录啊,faysky2在帮忙一下了
      

  8.   

    你的 strsql 并没有被执行。If (Text10.Text <> "") Then
     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
      

  9.   

    If (Text10.Text <> "") Then
      '语句有问题 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