如何从Datatable中查找行

时间:2017-02-15 08:02:31

标签: database vb.net datatable

我正在使用具有密码重置功能的登录系统。我想弄清楚如何从匹配的用户名输出秘密问题。我的想法是获取匹配用户名的行索引,然后使用行索引输出问题。是否可以将返回的行索引放在变量中?我是vb.net soooo的新手,如果你有更好的想法让我知道,我会感谢你的回报:P

Dim con As SqlConnection
Dim command As SqlCommand
Dim ad As SqlDataAdapter
Dim ds As DataSet
Public constring As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\almond\Desktop\Ticket System\Ticket System\Database.mdf;Integrated Security=True;User Instance=True"

 If TextBox1.Text = "" Then
        MessageBox.Show("Please enter your username")
    End If
    Dim q2 As String = "SELECT * FROM tblusers WHERE username = @username "

    con = New SqlConnection
    con.ConnectionString = constring
    con.Open()
    Dim command As New SqlCommand(q2, con)
    command.Parameters.Add("@username", SqlDbType.NChar).Value = TextBox1.Text
    Dim ad As New SqlDataAdapter(command)
    ad = New SqlDataAdapter(command)
    Dim table As New DataTable
    ad.Fill(table)

    If table.Rows.Count() = 0 Then
        MessageBox.Show("Account Not Found")
        Exit Sub
    End If
    con.Close()
End Sub

0 个答案:

没有答案