|
Answer» I have a database (ms-access), i can delete, update all those things but i have implemented a login page that USERS must enter to access to specific rihgts. Oh its a windows application.
The user filed is users in the DB.
/*
// Db Connection Try OpenDB() comm.Connection = conn conn.Close() Catch ee As Exception MsgBox(ee.Message) End Try Public Class Login
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim Surname As String Dim Password As String
Surname = txtUsername.Text Password = txtPassword.PasswordChar lblError.Text = "Sorry Wrong password/username" End Sub End Class */
I'm not too good with VB/VS i only started with it this year Feb.I'm guessing that you used the Data Source Configuration Wizard for the database connection. The ALSO seems to be a missing SQL statement to execute against the database.
Try defining a new Dataset object, a OleDb.OleDbDataAdapter object, and a SQL SELECT string. Execute the SQL statement on the dataadapter and use the dataadapter's FILL method to POPULATE the dataset. By using the dataset tables rows.count method you can determine if you returned any records. If so, you have a hit and the username and password are correct, otherwise there is an error.
Code: [Select]Dim ds As New DataSet Dim da As OleDb.OleDbDataAdapter Dim sql As String = "Select * From dbTablename where inUsername = dbUsername And inPswd = dbPswd"
da = New OleDb.OleDbDataAdapter(sql, dbConnect) da.Fill(ds, "dbTablename") If ds.Tables("dbTablename").Rows.Count = 1 Then Else lblError.Text = "Sorry Wrong password/username" End If
You would have to fill in real world values for the names of dbTablename which is the table where the users/passwords are stored and dbConnect which is the data item that holds the connection string. You also NEED to fixup the SQL statement.
Good luck. Thanks Man i think i'll get it right now i pn;y needed a push but will notify if it works or not..
Thanks god blessThe code helped a bit "in java its easy"..i have a Access DB with a table Users where a username and a password is stored. i want when i login with the deatails it should verify it with the one stored in the table and it match them, then direct me to Form1 page when it correct, if its wrong username or password the msg desplays or either msgbox and still at the loin page.
The connection i have defined my self. here is the connection class (Module)
Module Connection Public conn As New OleDb.OleDbConnection Public comm As New OleDb.OleDbCommand Public reader As OleDb.OleDbDataReader Public str_conn As String
Public Sub OpenDB() str_conn = "Provider=Microsoft.JET.OLEDB.4.0;Data Source=C:\Documents and Settings\fortunatom\My Documents\Visual Studio Projects\ConnectionTesting\AddressBook.mdb;" If conn.State = ConnectionState.Closed Then conn.ConnectionString = str_conn conn.Open() End If End Sub End Module
This is the delete class and the rest is working perfectly and this delete class is also working
Dim namee As String Private Sub frmDelete_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load OpenDB() comm.Connection = conn comm.CommandText = "select Name from address" reader = comm.ExecuteReader
While reader.Read cboDelete.Items.Add(reader(0)) End While conn.Close() End Sub
Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click namee = cboDelete.Text Try OpenDB() comm.Connection = conn comm.CommandText = "delete from address where Name = '" & namee & "'" comm.ExecuteNonQuery() conn.Close() MsgBox("details was Deleted!") Catch ee As Exception MsgBox(ee.Message) End Try Me.Close() End Sub End Class
Quote from: Sidewinder on June 25, 2007, 12:42:42 PM I'm guessing that you used the Data Source Configuration Wizard for the database connection. The also seems to be a missing SQL statement to execute against the database.
Try defining a new Dataset object, a OleDb.OleDbDataAdapter object, and a SQL SELECT string. Execute the SQL statement on the dataadapter and use the dataadapter's fill method to populate the dataset. By using the dataset tables rows.count method you can determine if you returned any records. If so, you have a hit and the username and password are correct, otherwise there is an error.
Code: [Select]Dim ds As New DataSet Dim da As OleDb.OleDbDataAdapter Dim sql As String = "Select * From dbTablename where inUsername = dbUsername And inPswd = dbPswd"
da = New OleDb.OleDbDataAdapter(sql, dbConnect) da.Fill(ds, "dbTablename") If ds.Tables("dbTablename").Rows.Count = 1 Then Else lblError.Text = "Sorry Wrong password/username" End If
You would have to fill in real world values for the names of dbTablename which is the table where the users/passwords are stored and dbConnect which is the data item that holds the connection string. You also need to fixup the SQL statement.
Good luck.
|