Solved

Querying Access To Insert into a database

Posted on 2007-04-05
4
202 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
vb6 programatically bring window to front 8 63
Validating VB6 Function 19 56
Best way to parse out a json string in VB6? 10 111
Adding to a VBA? 6 61
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

910 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now