Welcome to Dream.In.Code
Become an Expert!

Join 149,598 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,898 people online right now. Registration is fast and FREE... Join Now!




Querying Access Databases

 
Reply to this topicStart new topic

Querying Access Databases, Trying to update records in an Access database through my VB2005 Expre

Bort
11 Oct, 2007 - 06:48 AM
Post #1

D.I.C Regular
Group Icon

Joined: 18 Sep, 2006
Posts: 481



Thanked: 5 times
Dream Kudos: 350
My Contributions
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
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Querying Access Databases
11 Oct, 2007 - 09:18 AM
Post #2

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,482



Thanked: 161 times
Dream Kudos: 9050
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
You need a query like

SQL
update table_name set field1 = value1 where username = username and yourdatefield like getdate + '%'

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 11:37PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month