Solved

Querying Access To Insert into a database

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…

708 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

19 Experts available now in Live!

Get 1:1 Help Now