validation help

Steven Low

Active member
Joined
Apr 14, 2005
Messages
42
Programming Experience
1-3
Hi guys i am trying to do a validation for my database the below code adds a user to the database. So far i got the validation to display a message if theres a duplciation. But this message does not go away. i want this message to restart again. once clicked the button how would i do this

lb1.Text = "Username is already used" & vbCrLf & "Enter New User Name !" 'want this message to diapear once clicked on the button but its always there even if the add has been sucessul how can i get it to show different messages

Also i want to add a message which allows users to know that a user has been added sucessfully how would i do this and were would i insert it?:confused:

Thanks alot

VB.NET:
Dim Conn As OleDb.OleDbConnection ' <-- Configure this and open 
Dim OLEInsert As New OleDb.OleDbCommand
Conn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents proj.mdb;")
 
With OLEInsert
.Connection = Conn
.CommandText = "INSERT into us (user, pass, name) VALUES (?, ?, ?)"
 
 
.CommandType = CommandType.Text
' Set the parameters 
 
 
.Parameters.Add(New OleDb.OleDbParameter("usern", tx0.Text)) ' Where 'txtValue1' is the first value 
.Parameters.Add(New OleDb.OleDbParameter("passw", tx1.Text)) ' Where 
.Parameters.Add(New OleDb.OleDbParameter("namet", tx2.Text)) ' Where 
 
End With
' Execute 
Try
Conn.Open()
OLEInsert.ExecuteNonQuery()
Catch Ex As OleDbException
'MessageBox.Show(Ex.Message)
lb1.Text = "Username is already used" & vbCrLf & "Enter New User Name !"  
Finally
Conn.Close()
End Try
End Sub
 
How about this?

VB.NET:
lb1.Text = String.Empty
Dim Conn As OleDb.OleDbConnection ' <-- Configure this and open 
Dim OLEInsert As New OleDb.OleDbCommand
Conn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents proj.mdb;")
 
With OLEInsert
.Connection = Conn
.CommandText = "INSERT into us (user, pass, name) VALUES (?, ?, ?)"
 
 
.CommandType = CommandType.Text
' Set the parameters 
 
 
.Parameters.Add(New OleDb.OleDbParameter("usern", tx0.Text)) ' Where 'txtValue1' is the first value 
.Parameters.Add(New OleDb.OleDbParameter("passw", tx1.Text)) ' Where 
.Parameters.Add(New OleDb.OleDbParameter("namet", tx2.Text)) ' Where 
 
End With
' Execute 
Try
Conn.Open()
OLEInsert.ExecuteNonQuery()
lb1.Text = "Record save." 'Your information
Catch Ex As OleDbException
'MessageBox.Show(Ex.Message)
lb1.Text = "Username is already used" & vbCrLf & "Enter New User Name !"  
Finally
Conn.Close()
End Try
End Sub
 
Hi Steven,

Try these steps:

1. Change the user and name on the INSERT statement to [user] and [name], respectively.
2. Add a primary key constraint to field [user] to allow the application raise your error message while duplicate user entry detected.
 
Back
Top