Solved

Querying Access To Insert into a database

Posted on 2007-04-05
4
203 Views
Last Modified: 2013-11-25
I am doing a visual basic applications that is point of sale. It runs off a Access database to do the inserting
Every time my program compiles, it wipes my Inventory Database clean. What is wrong?

Private Sub buttonadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buttonadd.Click
        Dim connectionString As String = _
       "Provider=Microsoft.Jet.OLEDB.4.0;" & _
       "Data Source=" & Application.StartupPath & "\Inventory.mdb;" & _
       "User ID=Admin;" & _
       "Password="

        Dim logInOleDbConnection As New OleDbConnection(connectionString)

        ' Create a ADO.NET OleDbCommand.


        Dim sqlInventoryString As String = "INSERT INTO Inventory ([First Name],[Last Name],[Description],[Order Placed],[Order Shipped],[Order Recived],[Comments],[Shipping])  values('" & txtfirstname.Text & "','" & txtlastname.Text & "','" & txtdescription.Text & "', " & checkboxorderplaced.Checked & "," & checkboxordershipped.Checked & "," & checkboxorderreceived.Checked & ",'" & richtxtcomments.Text & "');"
        Dim sqlCommand As New OleDb.OleDbCommand(sqlInventoryString, logInOleDbConnection)
        ' Open the database connection.

        logInOleDbConnection.Open()

        ' Run the sqlCommand.
        Dim countFound As Integer = CType(sqlCommand.ExecuteScalar, Integer)

        ' Close the database connection.

        logInOleDbConnection.Close()

        ' If countFound = 1 a record with a matching UserName and Password
        ' was found..

        If countFound = 1 Then
            Label13.Text = "Insert Unsuccessful please try again"
        Else

            Label13.Text = "Insert Successful"
            txtfirstname.Clear()
            txtlastname.Clear()
            txtdescription.Clear()
            richtxtcomments.Clear()


        End If
0
Comment
Question by:jejernig
  • 2
4 Comments
 
LVL 42

Expert Comment

by:dqmq
ID: 18859389
>Every time it COMPILES it wipes the database clean????

Are you sure about that?  
0
 
LVL 2

Accepted Solution

by:
JSMCM earned 250 total points
ID: 18867601
Hi

>Every time it COMPILES it wipes the database clean????

As dqmq asked, are you sure? I would think its more likely that the database could be wiped clean if you are reinstalling a new version every time. If your setup program has a clean version of the database that usually gets installed with the software and you are running this setup program, it could overwrite your existing database.

John


0
 

Author Comment

by:jejernig
ID: 18868290
i am sorry i guess i did not make my question clear. Their is an existing access database (Inventory.mdb)each time i run my point of sell software the existing entries that are in the Inventory.mdb (YES i checked to see if they actualy got inserted) from the previous time I ran the program are missing. I hope that made a little more sense. Its not litterly wiping my access program just the entries in the database
0
 

Author Comment

by:jejernig
ID: 18885225
I found the answer there was a dataset that was over writing my database. Thanks for the help
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question