Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Querying Access To Insert into a database

Posted on 2007-04-05
4
Medium Priority
?
207 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 750 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

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses

704 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