将值与数据库中的现有值一起添加

时间:2014-09-10 13:11:30

标签: .net

我正在开发一个应用程序,我希望它更新一些信息,并将现有数据库中的数量值添加到用户输入的新值中。它正在更新,但不是一起添加数量,而是将新值放在数据库中现有值的d后面,例如,如果我之前在数据库中有5个,而在新文本框中有3个而不是新值为8,那么它显示为35数据库。这是我的代码,如何添加值             con = New OleDbConnection(“Provider = Microsoft.Jet.Oledb.4.0; Data Source =”& Application.StartupPath&“\ pharmacy.mdb”)             con.Open()             Dim ct1 As String =“select * from stock where code ='”& TxtCode.Text& “'”

        cmd = New OleDbCommand(ct1)
        cmd.Connection = con
        rdr = cmd.ExecuteReader()

        If rdr.Read Then

            con = New OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0; Data Source=" & Application.StartupPath & "\pharmacy.mdb")
            con.Open()

            Dim cb As String = "UPDATE stock SET company = @d1 , Productname =@d2, code=@d3, quantity= [quantity] + @d4, unitPrice = @d5, ddate = @d6, batchNo = @d7, Type = @d8, expDate =@d9 " + "WHERE code = @d3"

            cmd = New OleDbCommand(cb)

            cmd.Connection = con


            cmd.Parameters.Add(New OleDbParameter("@d1", "company"))
            cmd.Parameters.Add(New OleDbParameter("@d2", "productName"))


            cmd.Parameters.Add(New OleDbParameter("@d3", "code"))

            cmd.Parameters.Add(New OleDbParameter("@d4", "quantity"))

            cmd.Parameters.Add(New OleDbParameter("@d5", "unitPrice"))
            cmd.Parameters.Add(New OleDbParameter("@d6", "ddate"))
            cmd.Parameters.Add(New OleDbParameter("@d7", "batchNo"))
            cmd.Parameters.Add(New OleDbParameter("@d8", "type"))
            cmd.Parameters.Add(New OleDbParameter("@d9", "expDate"))



            cmd.Parameters("@d1").Value = CmbCompany.Text
            cmd.Parameters("@d2").Value = TxtPrdtName.Text

            cmd.Parameters("@d3").Value = TxtCode.Text


            cmd.Parameters("@d4").Value = TxtQuantity.Text

            cmd.Parameters("@d5").Value = (TxtunitPrice.Text)
            cmd.Parameters("@d6").Value = TxtDate.Text
            cmd.Parameters("@d7").Value = TxtBatchNo.Text()
            cmd.Parameters("@d8").Value = CmbType.Text
            cmd.Parameters("@d9").Value = dtpExpirationDate.Text


            cmd.ExecuteReader()

            MessageBox.Show("Successfully updated", "Product Details", MessageBoxButtons.OK, MessageBoxIcon.Information)

            rdr.Close()
            con.Close()

0 个答案:

没有答案