Hi all,
I've been developing a program in VB2005 Express Edition which keeps track of staff working hours. Basically, when you come in first thing in the morning, you sign in using the program and it saves a record in a table. All of this is working fine. My problem starts when it comes to signing out. How do I find the correct record in the table which corresponds with the person signing in? And, how do I update it?
Here is my code so far:
CODE
If InRadioButton.Checked = True Then
'Creates new row in Time Database
Dim NewEntry As Reg_v2DataSet.TimeRow
NewEntry = Me.Reg_v2DataSet.Time.NewTimeRow()
'Saves basic information from form into new database row
NewEntry.Item("FirstName") = NameBox.Text
NewEntry.Item("Date") = DateBox.Text
NewEntry.Item("TimeIn") = TimeString
NewEntry.Item("SignatureInData") = SigString
'MessageBox.Show(SigString)
'Adds new row to saved database
Me.Reg_v2DataSet.Time.Rows.Add(NewEntry)
Me.TimeTableAdapter1.Update(Reg_v2DataSet.Time)
'Confirms save
MessageBox.Show("Saved!")
'saves final information to database
Reg_v2DataSet.AcceptChanges()
'Updating the same row as above, only for signing out.
ElseIf OutRadioButton.Checked = True Then
'SQL Query to retrieve the signer's last record
Dim myConnection As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source='D:\Documents and Settings\office pc\My Documents\Visual Studio 2005\Projects\Register v7.0\Register v7.0\Reg v2.mdb'")
Dim SQLQuery As String = "SELECT MAX(EntryID) WHERE FirstName = NameBox.Text and TimeOut = NULL"
Dim SignOut As New OleDbCommand(SQLQuery, myConnection)
.Item("TimeOut") = TimeString
.Item("SignatureOutData") = SigString
Me.TimeTableAdapter1.Update(Reg_v2DataSet.Time)
'Confirms save
MessageBox.Show("Saved!")
'saves final information to database
Reg_v2DataSet.AcceptChanges()
Else
The first bit works fine (saving sign in data), I suspect the SQL query bit works fine, but because the ".Item" lines aren't working, I can't test it.
Could someone please take a look at this and let me know what you think?
Thanks,
Bort
This post has been edited by Bort: 11 Oct, 2007 - 06:52 AM