ID and password using a DataBase

alex_ea_2a

Member
Joined
Mar 2, 2006
Messages
8
Programming Experience
Beginner
I have two textboxes designed for an ID and a password. This form is connected to a database that contains a table with ID's a passwords. The form also has a button and a hidden image.

If the ID and passwords matches correctly with the information on the database, after clicking the button the image will display.

So far I have the adapter, the connection and the dstList correctly setup. The problem is to tell the computer that the textbox is a field on the database. Can you give me a hint or samples to solve this problem???? I'm so lost!!!
 
I had a problem similar to that. Here is the code that I ended up using!! Hope this helps you out!!!!

'This is the connection to the database
Dim conn As String = "(Your connection goes here)"
'Creates a new Sql Connection
Dim Securityconn As New SqlConnection(conn)
'Creates a Sql command and sets the employee # and password to the correct parameters
Dim myCommand As New SqlCommand("SELECT COUNT(*) FROM (name of table) WHERE (name of column in table of your username) = @USERID AND (name of column of password in table) = @Password", Securityconn)
myCommand.Parameters.Add("@UserID", txtID.Text)
myCommand.Parameters.Add("@Password", txtPassword.Text)
'Opens the connection
Securityconn.Open()
'Shows image if the username and password are correct
If CInt(myCommand.ExecuteScalar()) = 0 Then
(what you want it to do if there isn't an existing username and password)
Else
(insert code to show image)
End If
'Closes the connection
Securityconn.Close()
End Sub
 
SqlConnection

It does not let me dubbug because SqlConnection is not declared. do I have to create a public method or the code has to be loaded on main method?
 
You have to make sure that you put your connection in the line that says
Dim conn as string = ""

Your connection to your database goes inside of those quotes. Once you have established that connection there, you should be able to run the program and it work
 
http://www.geocities.com/alex_ea_2f/image.JPG, here is my image of how my application looks like, and here is the code, I still have the problem with SqlCommand. Thanks for your help


'Connection to the database
Dim conn As String = "OleDbConnection1"
'Creates a new sql connection
Dim Securityconn As New SqlCommand(conn)
'opens the connection
Dim myCommand As New SqlCommand("SELECT COUNT(*) FROM (LogIn) WHERE (ID Employee)= @USERID AND (Password) = @password", Securityconn)
myCommand.Paremeters.add("@userID", txtEmployeeID.Text)
myCommand.Parameters.add("@password", txtEmpPassword.Text)
'show image if the username and password are correct
Securityconn.open()
If CInt(mycommand.executeScalar()) = 0 Then
Me.lblDenied.Visible = True
Else
Me.lblGranted.Visible = True
'closes connection
securityconn.close()
End If
 
Up at the top of the code.. before anything else.... type this:
Imports System.Data.SQLClient

And change this
Dim Securityconn AsNewSqlCommand(conn)
BACK to this:
Dim Securityconn AsNewSqlConnection(conn)


Onething you haven't mentioned is the database type.. Access, SQL Server, Oracle or what?

Lastly, the connectionstring in jacked. It's not even close to being right. And until I know what DB you are using, we're not going to get that fixed.

-tg
 
Back
Top