Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hell All, I have written a timelog program with VB which allows for the addition of employees/associates.I noticed that when the user enters a name and wage and presses the "add associate" button that the new data/associate info does not immediately get written to the excel file. the program has to be closed before the excel file is updated. Is there a way to have the new associate data saved to the excel file right after the "add' button is pressed. My code for adding an associate is below. Any help is greatly appreciated!

What I have tried:

Using con As New OleDbConnection(connString)
               Dim dtAssoc As New DataTable
               Dim oda As New OleDbDataAdapter()
               Try
                   con.Open()
                   Dim cmd As New OleDbCommand()
                   oda.InsertCommand = cmd
                   cmd.Connection = con
                   cmd.CommandText = "INSERT INTO Associates (Assoc_ID, Assoc_Name, Assoc_Wage) VALUES (@Assoc_ID, @Assoc_Name, @Assoc_Wage)"
                   cmd.Parameters.AddWithValue("@Assoc_ID", adAssocID.ToString)
                   cmd.Parameters.AddWithValue("@Assoc_Name", adAssocName.ToString)
                   cmd.Parameters.AddWithValue("@Assoc_Wage", adAssocWage)
                   cmd.ExecuteNonQuery()

               Catch ex As Exception
               Finally
                   con.Close()
               End Try
               MsgBox("Associate added")
           End Using
Posted
Comments
PIEBALDconsult 8-Jun-17 20:23pm    
Well, maybe stop using Excel?
And definitely stop swallowing Exceptions.
Member 13197019 10-Jun-17 8:10am    
Thanks for your comment. I want to use a database that doesn't require the end user to have Excel or SQL installed on their computer. Do you have any suggestions? Thx.
PIEBALDconsult 10-Jun-17 11:50am    
SQL Server CE.
Member 13197019 11-Jun-17 7:49am    
Thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900