Solved

Querying Access To Insert into a database

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

820 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