0

studentrecords 表.,., 包含 IDNumber,LastName,Course,Firstname

我将使用 IDNumber 通过我的系统登录,一旦我进入主窗体,我想使用 IDNumber 作为主键显示 LASTname 和课程到主窗体中的 2 个文本框。,我的代码错误

将 con 调暗为新的 OleDbConnection 将 cmd 调暗为新的 OleDbCommand

  Dim da As New OleDbDataAdapter

  Dim dt As New DataTable

  Dim sSQL As String = String.Empty

  'get connection string declared in the Module1.vb and assing it to conn variable

  con = New OleDbConnection(Get_Constring)

  con.Open()

  cmd.Connection = con

  cmd.CommandType = CommandType.Text
  sSQL = "SELECT  LastName FROM studentsrecords where IDNumber like '%" & studentslogin.[txtIDNumber].Text & "%' order by ID desc"

  cmd.CommandText = sSQL

  da.SelectCommand = cmd

  da.Fill(dt)

  'evalutionrate.[lbllogin].Text = studentslogin.[txtIDNumber].Text

  evalutionrate.[lbllogin].Text = sSQL

  evalutionrate.Show()
4

1 回答 1

-1

在这里:只需创建一个新标签“label= lbllogin”并将其“隐藏”在 Welcome 或 mainform 中,因为它将是读取数据库的关键。

Private Sub Mainform_Load(sender As Object, e As EventArgs) Handles MyBase.Load
 If conn.State = ConnectionState.Closed Then
        conn.Open()
    End If
    lbllogin.Text = Login.studentslogin.Text
    Dim sqlquery As String = "select * from studentsrecords where IDNumber =@ID"
    Dim sqlcommad As New OleDbCommand
    Dim sqlread As OleDbDataReader
    sqlcommad.CommandText = sqlquery
    sqlcommad.Connection = conn
    sqlcommad.Parameters.AddWithValue("@ID", lbllogin.Text)
    sqlcommad.ExecuteNonQuery()
    sqlread = sqlcommad.ExecuteReader
    Try
        If (sqlread.Read()) Then
            textbox1.Text = sqlread("LASTname ")      
            textbox2.Text = sqlread("course ")

        End If
    Catch ex As Exception

    End Try
    conn.Close()
End Sub

如果此答案有用,请不要忘记投票。

于 2013-10-03T01:47:12.817 回答