I having been working on this piece of code of several days now and i am not getting anywere i could really do with some advise.
What i am trying to do is get my system to look into the database and recognize if the user is a admin or a user, based on that they have certain rights
below is my code
Imports MySql.Data.MySqlClient
Imports System.Data.SqlClient
Public Class Form3
Public con As New SqlConnection("server=; user =; password=; database=;")
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim conn As MySqlConnection
conn = New MySqlConnection()
conn.ConnectionString = "server=; user =; password=; database=;"
' See if connection failed
Try
conn.Open()
Catch myerror As MySqlException
MsgBox("Error1!")
End Try
' SQL Query
Dim myAdapter As New MySqlDataAdapter
Try
con.Open()
Dim com As New SqlDataAdapter("select * from login where userName='" + txtusername.Text + "'", con)
Dim ds As New DataSet
ds.Clear()
com.Fill(ds)
If ds.Tables(0).Rows.Count > 0 Then
If ds.Tables(0).Rows(0)(1).ToString.Trim = txtpassword.Text.Trim Then
MsgBox("Login Successfull!")
If ds.Tables(0).Rows(0)(2).ToString.Trim = "Admin" Then
MainFrm.btnDelete.Enabled = True
Else
MainFrm.btnDelete.Enabled = False
End If
MainFrm.Show()
Else
MsgBox("Invalid Username and Password!!")
End If
Else
MsgBox("Invalid Username and Password!!")
End If
Catch ex As Exception
MsgBox(ex.Message)
Finally
con.Close()
End Try

New Topic/Question
Reply



MultiQuote





|