This code defines how to use the DataReader in windows programming for Fetching Data.

Imports System.Data.SqlClient

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim str As String = "Data Source=.;uid=sa;pwd=123;database=master"

        Dim con As New SqlConnection(str)

        con.Open()

        Dim com As String = "Select username from logn where username='" & txtuser.Text & "' and  password ='" & txtpass.Text & "';"

        Dim cm As New SqlCommand(com, con)

        Dim rd As SqlDataReader = cm.ExecuteReader()

        If rd.Read() = True Then

            MessageBox.Show("Valid username and password")

        Else

            MessageBox.Show("Invalid username and password", caption:="login")

            txtuser.Clear()

            txtpass.Clear()

        End If

    End Sub

End Class