在mysql查询中,如何从数据库中获取值?

在mysql查询中,如何从数据库中获取值?,mysql,vb.net,Mysql,Vb.net,所以我们有一个登录表单,在这个表单中,程序必须检测用户被分配到的位置。(选择位置是在注册过程中完成的,因此用户的位置已保存到数据库中)。据推测,每个职位都有一个单独的形式 Dim username As String = txtUser.Text Dim password As String = txtPass.Text //check if username and password exist checklogin(username, password) If RS.EO

所以我们有一个登录表单,在这个表单中,程序必须检测用户被分配到的位置。(选择位置是在注册过程中完成的,因此用户的位置已保存到数据库中)。据推测,每个职位都有一个单独的形式

Dim username As String = txtUser.Text
Dim password As String = txtPass.Text

//check if username and password exist
 checklogin(username, password)
        If RS.EOF Then
            MessageBox.Show("Mismatch Entry", "confirmation Message", MessageBoxButtons.OKCancel, MessageBoxIcon.Error)
            txtUser.Clear()
            txtUser.Focus()
        Else
            Me.Hide()
            //problem starts here
            checkposition()
            If (position == "Officer")
                OfficerForm.Show()
            Elseif (position == "Head")
                HeadForm.Show()
            Elseif (position == "Admin")
                AdminForm.Show()
            Else
             // dialog box
        End If
    End Sub
检查位置的方法:

Public Sub checkpositon(ByVal username As String, ByVal positon As String)
    RS = CN.Execute("SELECT position FROM admin WHERE uName = '" & username & "' ")
End Sub
我知道代码中还缺少一些东西。我知道这有什么问题。 如何将数据库中的位置检索到登录表单中?请帮助:(
谢谢!

函数checkposition()的第二个参数应命名为“position”,而不是“position”。此外,您还需要为position赋值,例如

position = RS.Fields.Item(0);

你也应该避免用户名的值,以及

你很容易受到SQL注入攻击。总是使用SQL参数而不是字符串连接。考虑“代码>用户名<代码>是代码>;丢弃表管理;-< /COD>。但是这是我们在学校里做的。有点短。很遗憾,这是通用的。请显示链接到YO。你的朋友们。你指的是职位的哪一部分?我知道我必须使用RS。但我不知道.CN.Execute将如何返回记录集(RS)。我猜你只会期望一个结果,否则你会在执行查询后检查RS.EOF。我对我的答案做了一些更改。我现在明白了。谢谢^^