please someone help me..im doing my final project and below is my code for the registration form..after i fill up all my form and it will appear a msg box that i can only register once...the data is not being inserted in the database..im using ms access...please2....do help me...i dont know what is wrong...
Imports System.Data.OleDb
Imports System.Text.RegularExpressions
Public Class registration
Private _Userid As Int32 = 0
Public Property Userid() As Int32
Get
Return _Userid
End Get
Set(ByVal value As Int32)
_Userid = value
RetrieveContactDetails()
End Set
End Property
Private Sub RetrieveContactDetails()
Dim conn As New OleDbConnection("provider=microsoft.jet.OleDB.4.0;Data Source=D:\fnal projek\khurasan.mdb; Persist Security Info = false;")
Dim command As New OleDbCommand("Select Username, Password, Name, NumIC, Gender, Email, Address, PhoneNum from Customer Where Userid = " & _Userid, conn)
conn.Open()
Dim contactReader As OleDbDataReader = command.ExecuteReader
contactReader.Read()
TxtUname.Text = contactReader("Username").ToString
TxtPwd.Text = contactReader("Password").ToString
TxtName.Text = contactReader("Name").ToString
TxtICNum.Text = contactReader("NumIC").ToString
cmboxGndr.Text = contactReader("Gender").ToString
TxtMail.Text = contactReader("Email").ToString
Rtxtadd.Text = contactReader("Address").ToString
TxtPhone.Text = contactReader("PhoneNum").ToString
conn.Close()
End Sub
Private Sub Label4_Click(sender As System.Object, e As System.EventArgs) Handles Label4.Click
End Sub
Private Sub PictureBox1_Click(sender As System.Object, e As System.EventArgs) Handles PictureBox1.Click
Dim dialogResult As DialogResult
dialogResult = MsgBox("Are you sure you want to leave this system ? ", vbYesNo + vbExclamation, "Khurasan Online")
If dialogResult = dialogResult.Yes Then
Me.Close()
Me.Dispose()
End If
End Sub
Private Sub PictureBox2_Click(sender As System.Object, e As System.EventArgs) Handles PictureBox2.Click
Dim dialogResult As DialogResult
dialogResult = MsgBox("Are you sure you want to leave this page ? ", vbYesNo + vbExclamation, "Khurasan Online")
If dialogResult = dialogResult.Yes Then
Me.Close()
welcomepage.Show()
End If
End Sub
Private Sub TxtName_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles TxtName.KeyPress
Dim ch As Char = e.KeyChar
If Char.IsDigit(ch) Then 'restricting txtUname to input only characters
e.Handled = True
End If
End Sub
Private Sub registration_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub TxtPhone_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles TxtPhone.KeyPress
Dim ch As Char = e.KeyChar
If Char.IsLetter(ch) Then 'restricting txtphone to input only digit
e.Handled = True
End If
End Sub
Private Sub BttnSbmit_Click(sender As System.Object, e As System.EventArgs) Handles BttnSbmit.Click
Dim conn As New OleDbConnection("provider=microsoft.jet.OleDB.4.0;Data Source=D:\fnal projek\khurasan.mdb; Persist Security Info = false;")
Dim sql As String = String.Empty
Dim Fon As String = Val(TxtPhone.Text)
Dim IC As String = Val(TxtICNum.Text)
Dim email As New Regex("^([\w\-]+\.)*[\w\-]+@([\w\-]+\.)+([\w\-]{2,3})$")
If TxtICNum.Text = "" Then
MsgBox("Please enter the IC number", MsgBoxStyle.Critical, "Khurasan Online")
ElseIf TxtUname.Text & TxtICNum.Text & Rtxtadd.Text & TxtPwd.Text & TxtName.Text & TxtMail.Text & TxtRemail.Text = "" Then
MsgBox("Please fill all the empty field", MsgBoxStyle.Critical, "Khurasan Online")
ElseIf email.IsMatch(TxtMail.Text) = False Then
MsgBox("Please insert correct email address", MsgBoxStyle.Critical, "Khurasan Online")
ElseIf Fon.Length < 9 Or Fon.Length > 9 Then
MsgBox("Please enter the correct Phone number", MsgBoxStyle.Critical, "Khurasan Online")
ElseIf IC.Length < 12 Or IC.Length > 12 Then
MsgBox("Please enter the correct IC number", MsgBoxStyle.Critical, "Khurasan Online")
Else
If _Userid = 0 Then
sql = "insert into Customer(Username, Password, Name, NumIC, Gender, Email, Address, PhoneNum)" & "values ('" & TxtUname.Text & "', '" & TxtPwd.Text & "','" & TxtName.Text & "','" & TxtICNum.Text & "','" & cmboxGndr.Text & "', '" & TxtMail.Text & "','" & Rtxtadd.Text & "','" & TxtPhone.Text & "' ) "
Else
sql = "update Customer Username = '" & TxtUname.Text & "', Password = ' " & TxtPwd.Text & " ', Name = ' " & TxtName.Text & " ', NumIC = ' " & TxtICNum.Text & " ', Gender = ' " & cmboxGndr.Text & " ', Email = ' " & TxtMail.Text & " ', Address = ' " & Rtxtadd.Text & " ', PhoneNum = '" & TxtPhone.Text & "' Where Userid =" & _Userid
End If
Try
conn.Open()
Dim Command As New OleDbCommand(sql, conn)
Command.ExecuteNonQuery()
MsgBox("Success !!!", MsgBoxStyle.Information, "Khurasan Online")
Catch ex As Exception
MsgBox("You can only register once !!!", MsgBoxStyle.Exclamation, "Khurasan Online")
End Try
conn.Close()
End If
End Sub
End Class