1.11M Members

from database to listview


I have this code:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim connection As New SqlClient.SqlConnection
        Dim command As New SqlClient.SqlCommand
        Dim adaptor As New SqlClient.SqlDataAdapter
        Dim dataset As New DataSet

        connection.ConnectionString = ("Data Source=.\SQLEXPRESS;AttachDbFilename=c:\users\korisnik\documents\visual studio 2010\Projects\WindowsApplication46\WindowsApplication46\Database2.mdf;Integrated Security=True;User Instance=True")
        command.CommandText = "SELECT * FROM [User] WHERE (username='" + TextBox1.Text + "')AND (password='" + TextBox2.Text + "');"

        command.Connection = connection
        adaptor.SelectCommand = command
        adaptor.Fill(dataset, "1")
        Dim count = dataset.Tables(0).Rows.Count)
        If count > 0 Then

            MsgBox("Bad username or password!!")

        End If
    End Sub

Now, I want the code in the loop if. actually when I press the button, and in the textbox is a number which coincides with the number in the database,then get the records from a database in a listview, how to do that?
something like this:

if textbox.text= fild in a database then

print the fild from database to listview

else msg("no item!")

end if



This article has been dead for over six months: Start a new discussion instead
Start New Discussion
Tags Related to this Article