tyueban 2021-06-17 19:59 采纳率: 33.3%
浏览 23
已采纳

vb.net登录遇到的问题

我使用第一个账号登录,进入主菜单后,点击返回登录,重新输入另一个账号信息,登录主菜单显示还是上一个账号的信息,求助,这是登录页面的代码

Imports System.Data.SqlClient

Public Class login
    Dim Conn As SqlConnection
    Public sf As String

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles regist.Click
        register.Show()

    End Sub

    Private Sub log_Click(sender As System.Object, e As System.EventArgs) Handles log.Click
        Dim name, pad As String
        name = yname.Text
        pad = ypad.Text
        If ComboBox1.SelectedIndex = 0 Then
            sf = "管理员"
        ElseIf ComboBox1.SelectedIndex = 1 Then
            sf = "挂号员"
        Else
            sf = "医生"
        End If
        If name = "" Then
            MessageBox.Show("用户名不能为空")
        ElseIf pad = "" Then
            MessageBox.Show("密码不能为空")
        Else

            Conn = New SqlConnection()
            Conn.ConnectionString = "Server=(local);database=mzgh;Integrated Security=True"
            Conn.Open()
            Dim Comm As New SqlCommand("select * from yhxx where y_name='" & name & "' and y_pad='" & pad & "'", Conn)
            Dim ds As DataSet = New DataSet
            Dim da As New SqlDataAdapter
            da.SelectCommand = Comm
            da.Fill(ds, "yhxx")
            If ds.Tables("yhxx").Rows.Count = 0 Then
                MsgBox("用户名或密码错误,请重新输入!")
            Else
                MsgBox("登录成功!")
                Me.Hide()
                Main.Show()
            End If
            Conn.Close()

        End If


    End Sub

    Private Sub cancel_Click(sender As System.Object, e As System.EventArgs) Handles cancel.Click
        yname.Text = ""
        ypad.Text = ""
    End Sub

    Private Sub log_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles log.MouseDown
        Dim n As String
        n = yname.Text
        Conn = New SqlConnection()
        Conn.ConnectionString = "Server=(local);database=mzgh;Integrated Security=True"
        Conn.Open()
        Dim Comm As New SqlCommand("select y_name from yhxx where y_name='" & n & "'", Conn)
        Dim ds As DataSet = New DataSet
        Dim da As New SqlDataAdapter
        da.SelectCommand = Comm
        da.Fill(ds, "yhxx")
        If ds.Tables("yhxx").Rows.Count = 0 Then
            MsgBox("用户名不存在,请先注册!")
       
        End If
        Conn.Close()
    End Sub
End Class

这是主菜单代码

 

  • 写回答

4条回答 默认 最新

  • CSDN专家-showbo 2021-06-17 21:34
    关注

      没看到你设置登录用户身份信息的代码。。

     

    main窗体是通过login窗体的sf这个变量控制这里显示?

     

    检查main窗体代码,添加form_load更新下表单的Me.Text属性

     

    对你有帮助能点个采纳吗,谢谢~~

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题