2013-10-03 49 views
0

studentrecords表,。,包含IDNumber中,姓氏,當然,名字加載數據到我的MainForm

我將通過使用IDNumber中我的系統,一旦我去MainForm的iwant顯示姓氏,當然到2登錄。文本框在使用的IDNumber作爲其主鍵的MainForm,我的代碼錯誤

昏暗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() 

回答

-1

這裏:只是做一個新的標籤「標籤= lbllogin並「隱藏」它歡迎或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 [email protected]" 
    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 

如果此答案有用,請不要忘記投票。

+0

它只加載IDNumber –