Basicaly I need help to make the code to check if the username is in the database already and then return an error screen if it is or just continue the code and write it.
Imports System.Data
Public Class Form2
Dim inc As Integer
Dim MaxRows As Integer
Dim con As New OleDb.OleDbConnection
Dim ds As New DataSet
Dim da As OleDb.OleDbDataAdapter
Dim sql As String
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\Accounts.mdb;Jet Oledb:Database Password=kas;"
con.Open()
sql = "SELECT * FROM tblAccounts"
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, "Accounts")
con.Close()
MaxRows = ds.Tables("Accounts").Rows.Count
inc = 0
End Sub
Private Sub NavigateRecords()
TextBox1.Text = ds.Tables("Accounts").Rows(inc).Item(1)
TextBox2.Text = ds.Tables("Accounts").Rows(inc).Item(2)
End Sub
Private Sub btnCreate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreate.Click
If TextBox1.Text = "" Then
'Show an Error Message.
MsgBox("Error, You need at least 1 Letter on your Username.")
ElseIf inc <> -1 Then
Dim cb As New OleDb.OleDbCommandBuilder(da)
Dim dsNewRow As DataRow
dsNewRow = ds.Tables("Accounts").NewRow()
dsNewRow.Item(1) = TextBox1.Text
dsNewRow.Item(2) = TextBox2.Text
ds.Tables("Accounts").Rows.Add(dsNewRow)
da.Update(ds, "Accounts")
TextBox1.Clear()
TextBox2.Clear()
MsgBox("Your account has been created.")
Form1.Show()
Me.Close()
End If
End Sub
Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
Me.Close()
Form1.Show()
End Sub
Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
TextBox2.PasswordChar = ("*")
End Sub
End Class
I created all of this off of a few tutorials that I found of some sites but they did not go into the database much.

New Topic/Question
Reply




MultiQuote



|