Hello all,
I am having a little issue I was hoping to get some help with. I am working on an app and everything was going great. I was able to write to my db and all feilds were working great, so then I wanted to add a user password confirmation before logging to the db. Well, I worked on that issue for a while and finally got it working properly (by reading many article here :).... (I also think there may be some sql issues with the way that I am confirming the password....but that can wait for now.....
All is good.....so I thought....
When I run the entire app, for some reason the loggin information is no longer working properly???? I then commented out the password confirmation section and the logging will work. So I am a little confussed why they will not work together. I would greatly appreciate it if someone could take a look and see where I went wrong.
Please be nice, I am a beginner with the vb stuff :) It to a very long time to get to this point and I do not realy understand all of the db connection stuff, so if possible write the reply so I will understand it..
Thanks in advance
`
Public Class BaleCutterLC
Private Sub TableLayoutPanel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs)
End Sub
'on user tab away from user name, app will confirm entry of password enterd to db password
Private Sub TextBox4_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox4.Leave
Dim connetionString As String
Dim oledbCnn As OleDbConnection
Dim oledbCmd As OleDbCommand
Dim sql As String
Dim UserPassword As String
'path to database location
connetionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Documents and Settings\DT\Desktop\PaperlessAppdbFolder\SecAccess.accdb;"
'sql statement looking for textbox entry
sql = "SELECT * FROM SecAccess WHERE User = '" & TextBox4.Text & "'"
'assign connection strinf to variable
oledbCnn = New OleDbConnection(connetionString)
'if exceptions catch and return error
Try
oledbCnn.Open()
oledbCmd = New OleDbCommand(sql, oledbCnn)
Dim oledbReader As OleDbDataReader = oledbCmd.ExecuteReader()
While oledbReader.Read
'assign read db password to usable variable
UserPassword = oledbReader.Item(2)
'assign password pop up box names
Dim message, title, defaultValue As String
Dim Confirmpassword As String
'pop up configurations
title = "Password Confirmation" 'Set title.
message = "Please enter your user password" 'Set prompt.
defaultValue = "" 'Set default value.
' Display dialog box at position 100, 100 and assign user input to variable Userpassword
Confirmpassword = InputBox(message, title, defaultValue, 100, 100)
'confirm passwrod and entered password match
If Confirmpassword = UserPassword Then
MsgBox("confirmed password")
End If
End While
'close connection to db
oledbReader.Close()
oledbCmd.Dispose()
oledbCnn.Close()
Catch ex As Exception
MsgBox("Can not open connection ! ")
End Try
End Sub
'if safety check < 8 hrs complete new form
Private Sub BaleCutLogButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BaleCutLogButton.Click
'Establish connection with BaleCutterLC db
Dim strConnection As String
Dim newconnection As OleDbConnection
strConnection = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Documents and Settings\DT\Desktop\PaperlessAppdbFolder\ADCBaleCutterLC.accdb;"
newconnection = New OleDbConnection(strConnection)
'Open connection to BaleCutterLC db
newconnection.Open()
Dim addstr As String = "INSERT INTO `ADCBaleCutterLC` (`Old Formula`, `New Formula`,`Raw Material Name`,`Raw Material Number`,`Batch Number`,`Preformed By`,`Preformed by Date`,`Verified By`,`Verified By Date`) VALUES (add1, add2, add3, add4, add5, add6, add7, add8, add9)"
Dim addnewcommand As New OleDb.OleDbCommand
addnewcommand.Connection = newconnection
addnewcommand.CommandText = addstr
'propmt user of empty feilds
If OldFormulaTextBox.Text = "" Then
MsgBox("Empty feilds not Allowed", MsgBoxStyle.Information, "Verify")
ElseIf NewFormulaTextBox.Text = "" Then
MsgBox("Empty feilds not Allowed", MsgBoxStyle.Information, "Verify")
ElseIf TextBox1.Text = "" Then
MsgBox("Empty feilds not Allowed", MsgBoxStyle.Information, "Verify")
ElseIf TextBox2.Text = "" Then
MsgBox("Empty feilds not Allowed", MsgBoxStyle.Information, "Verify")
ElseIf TextBox3.Text = "" Then
MsgBox("Empty feilds not Allowed", MsgBoxStyle.Information, "Verify")
ElseIf TextBox4.Text = "" Then
MsgBox("Empty feilds not Allowed", MsgBoxStyle.Information, "Verify")
ElseIf TextBox5.Text = "" Then
MsgBox("Empty feilds not Allowed", MsgBoxStyle.Information, "Verify")
ElseIf TextBox6.Text = "" Then
MsgBox("Empty feilds not Allowed", MsgBoxStyle.Information, "Verify")
ElseIf TextBox7.Text = "" Then
MsgBox("Empty feilds not Allowed", MsgBoxStyle.Information, "Verify")
End If
'read values from textboxes
addnewcommand.Parameters.AddWithValue("add1", OldFormulaTextBox.Text)
addnewcommand.Parameters.AddWithValue("add2", NewFormulaTextBox.Text)
addnewcommand.Parameters.AddWithValue("add3", TextBox1.Text)
addnewcommand.Parameters.AddWithValue("add4", TextBox2.Text)
addnewcommand.Parameters.AddWithValue("add5", TextBox3.Text)
addnewcommand.Parameters.AddWithValue("add6", TextBox4.Text)
addnewcommand.Parameters.AddWithValue("add7", TextBox5.Text)
addnewcommand.Parameters.AddWithValue("add8", TextBox6.Text)
addnewcommand.Parameters.AddWithValue("add9", TextBox7.Text)
Try 'exception capture
'write to db
addnewcommand.ExecuteNonQuery()
MsgBox("Batch information successfully logged")
'change color status of current RM
If TextBox1.Text > "" Then
TextBox1.BackColor = Color.LawnGreen
End If
If TextBox2.Text > "" Then
TextBox2.BackColor = Color.LawnGreen
End If
If TextBox3.Text > "" Then
TextBox3.BackColor = Color.LawnGreen
End If
If TextBox4.Text > "" Then
TextBox4.BackColor = Color.LawnGreen
End If
If TextBox5.Text > "" Then
TextBox5.BackColor = Color.LawnGreen
End If
If TextBox6.Text > "" Then
TextBox6.BackColor = Color.LawnGreen
End If
If TextBox7.Text > "" Then
TextBox7.BackColor = Color.LawnGreen
End If
Catch ex As Exception
End Try
'Close connection to db
newconnection.Close()
End Sub
Private Sub ReturnButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ReturnButton.Click
Dim oForm As MainForm
oForm = New MainForm()
oForm.Show()
'add save function if return button clicked*********************
'this opens a seconds main form*******************
'close form if return button clicked
Me.Close()
End Sub
Private Sub AddNewBatchButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddNewBatchButton.Click
Dim choice = MsgBox("Is this for the same formula", 4, "ALERT")
If choice = 7 Then 'yes 6 and no 7
NewFormulaTextBox.Text = OldFormulaTextBox.Text
OldFormulaTextBox.Text = ""
End If
If TextBox1.BackColor = Color.LawnGreen Then
TextBox1.Text = ""
TextBox1.BackColor = Color.White
TextBox2.Text = ""
TextBox2.BackColor = Color.White
TextBox3.Text = ""
TextBox3.BackColor = Color.White
TextBox4.Text = ""
TextBox4.BackColor = Color.White
TextBox5.Text = ""
TextBox5.BackColor = Color.White
TextBox6.Text = ""
TextBox6.BackColor = Color.White
TextBox7.Text = ""
TextBox7.BackColor = Color.White
Else : MsgBox("You must log the current batch before entering a new one")
End If
End Sub
End Class
`