Dim con As New OleDb.OleDbConnection ' declare connection object
Dim ds As New DataSet ' declare dataset
Dim da As OleDb.OleDbDataAdapter ' declare data adapter
Dim sql As String ' declare sql string
con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.;Data _
Source = C:\DatabaseName.mdb" ' assign technology and data source
con.Open() ' open connection
sql = "SELECT * FROM DatabaseTableName" ' assign sql statement
da = New OleDb.OleDbDataAdapter(sql, con) ' create data adapter
da.Fill(ds, "Dataset Name") ' fill data set and assign name
con.Close() ' close connection
ul = ds.Tables("Dataset Name").Rows.Count()
i = 0
While i <= ul
If i < ul Then
If txtUsername.Text = ds.Tables("UserInfo").Rows(i).Item("Username") And txtPassword.Text = ds.Tables("UserInfo").Rows(i).Item("Pass") Then
' Put Your Success Outcome here.
ElseIf i = ul Then ' At end of list
If Me.Visible = True Then ' still visible so user not found
MsgBox("ACCESS DENIED")
Else
' DO NOTHING
End If
End If
i = i + 1
End While
Yeah, but it's a good example of a bad start. Sorry...The code below will connect to a database, populate a dataset and use a data adapter to check if the values in two textboxes correspond to those values in the database.
People typically operate in the way they first learned and are quite resistant to change. THus if you show a newbie how to access a database using all the common nasty mistakes (putting reams of db code in button handlers, writing SQLs into the code as concatenated strings, digging stuff out of the database manually from the data reader, ignoring advanced type-specific functionality offered by modern constructs such as datasets) they will tend to carry on doing it in this crappy way that should have died with the passing of the 1990s..What did you mean by a good example of a bad start, just so I can improve on my style![]()