Login Form problem
Hello Sir,
I hav some problem in login form codding plz guide me , i am sending codding of this form,
mports System.Data.SqlClient
PublicClass Form1
Private constr AsString = "initial catalog=strack; data source=.; integrated security=true"
Private cn As SqlConnection
Private da As SqlDataAdapter
Private dt As DataTable
Private cmd As SqlCommand
PrivateSub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load
cn = New SqlConnection(constr)
cmd = New SqlCommand("Select unm from usrn order by unm asc", cn)
da = New SqlDataAdapter
da.SelectCommand = cmd
dt = New DataTable
da.Fill(dt)
ComboBox1.DataSource = dt
ComboBox1.DisplayMember = "UNM"
EndSub
PrivateSub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Close()
EndSub
PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
cn = New SqlConnection(constr)
cmd = New SqlCommand("SELECT count(*) FROM usrn Where unm = '" & ComboBox1.SelectedItem.ToString() & "' and upw = '" & TextBox1.Text & "'", cn)
'cmd = New SqlCommand("SELECT uid FROM usrn Where unm = '" & ComboBox1.SelectedItem.ToString() & "' and upw = '" & TextBox1.Text & "'", cn)
'Try
cn.Open()
'Catch ex As Exception
' MessageBox.Show("Error Connecting to Database: " & ex.Message)
'End Try
Dim i AsInteger
i = (cmd.ExecuteScalar()).ToString()
If (i = 1) Then
Form2.Show()
Else
MsgBox("Plz enter the correct password")
EndIf
'da.SelectCommand = cmd
'Dim dr As SqlDataReader = cmd.ExecuteReader()
'If (dr.HasRows = 1) Then
' 'MessageBox.Show("Invalid Login Details", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly, AcceptButton)
' Form2.Show()
'Else
'MsgBox("Invalid password")
'End If
cn.Close()
EndSub
EndClass
|