标题:求教 VB.NET+access 操作
只看楼主
linanfang721
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2014-4-22
 问题点数:0 回复次数:1 
求教 VB.NET+access 操作
定义了一个函数
    Sub ShowEmpInfo()
        Me.hr_nanme.Text = CurEmp.Emp_Name
        Me.hr_sex.Text = CurEmp.Sex
        Me.hr_num.Text = CurEmp.Emp_Num
        Me.hr_address.Text = CurEmp.Emp_Add
        Me.hr_intime.Text = CurEmp.Emp_intime
        Me.hr_outtime.Text = CurEmp.Emp_outtime
        Me.hr_memo.Text = CurEmp.Emp_Memo
    End sub
 
窗体有个listbox,需要加载 员工表 中的 员工姓名   
Private Sub Frm_hr_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
   LBUserName.Items.Clear()
        Dim SQLString As String = "SELECT * FROM 员工表"
        Dim MSG As String = ""
        '执行SQL查询语句
        Dim DTable As DataTable = DBoperation.DBoperate(SQLString, MSG)
        Dim UserRow As DataRow
        For Each UserRow In DTable.Rows
            LBUserName.Items.Add(UserRow("员工姓名"))
            LBUserName.ValueMember = "员工ID"
            LBUserName.SelectedValue = "员工ID"
            'LBUserName.DisplayMember = "员工姓名"
        Next
    End Sub


选择员工姓名时,窗体其他标签的内容读取Access表的信息显示


    Private Sub LBUserName_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LBUserName.SelectedIndexChanged
        If LBUserName.ValueMember = "" Then
            CurEmp.Init()
        End If
        CurEmp.GetInfo(CInt(LBUserName.SelectedValue))
        ShowEmpInfo()
    End Sub

但是怎么也实现不了,就是这个selectedValue传递有问题
搜索更多相关主题的帖子: access 姓名 
2014-04-22 21:56
linanfang721
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2014-4-22
得分:0 
这个 员工类 中定义的GetInfo 函数
程序代码:
  Public Function GetInfo(ByVal TemEmpId As Integer) As Boolean
        Dim SQLString As String
        Dim MSG As String = ""
        If TemEmpId <= 0 Then
            Init()
            GetInfo = False
            Exit Function
        End If
        Emp_Id = TemEmpId
        SQLString = "SELECT * FROM 员工表 WHERE 员工ID=" & Trim(Str(TemEmpId))
        Dim DTable As DataTable = DBoperation.DBoperate(SQLString, MSG)
        If DTable.Rows.Count < 1 Then
            GetInfo = False
            Exit Function
        Else
            Emp_Name = DTable.Rows(0)("员工姓名")
            Sex = DTable.Rows(0)("性别")
            Emp_Add = DTable.Rows(0)("联系地址")
            Emp_Num = DTable.Rows(0)("联系电话")
            Emp_intime = DTable.Rows(0)("入职时间")
            Emp_outtime = DTable.Rows(0)("离职时间")
            Emp_Memo = DTable.Rows(0)("备注")
        End If
        GetInfo = True
    End Function

2014-04-23 21:24



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-430497-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015234 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved