如果再次输入样式,我们如何通过ms visual basic添加ms访问量? [英] how can we add quantity in ms access via ms visual basic if a style is entered again?

查看:60
本文介绍了如果再次输入样式,我们如何通过ms visual basic添加ms访问量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  Imports  System.Data 

Imports System.Data.OleDb
公共 Form1
Dim cnnOLEDB As OleDb.OleDbConnection

Dim cmdOLEDB 作为 OleDbCommand

Dim cmdInsert As OleDbCommand

Dim cmdUpdate As OleDbCommand

Dim cmdDelete As < span class =code-keyword>新 OleDbCommand

Dim strConnectionString = Provider = Microsoft.ACE.OLEDB .12.0; Data Source = basic.accdb; Persist Security Info = False

Private Sub btnclear_Click( ByVal sender As System。 Object ByVal e As System.EventArgs)句柄 btnclear.Click
txtchln.Text =
txtbuyer.Text =
txtstyle.Text =
txtcolor.Text = < span class =code-string>
txtqty.Text =

结束 Sub

私有 Sub btnclose_Click( ByVal sender As 系统。对象 ByVal e 作为 System.EventArgs)句柄 btnclose.Click
.Close()

结束 Sub

私人 Sub Form1_Load( ByVal sender As 系统。对象 ByVal e As System.EventArgs)句柄 MyBase .Load

cnnOLEDB.ConnectionString = strConnectionString
cnnOLEDB.Open()

结束 Sub

私有 Sub btnenter_Click( ByVal sender As System。 Object ByVal e As System.EventArgs)句柄 btnenter.Click
Dim challan,买家,风格,颜色,数量
challan = txtchln.Text
buyer = txtbuyer.Text
style = txtstyle.Text
color = txtcolor.Text
qty = txtqty .Text

cmdInsert.CommandText = 插入基本值(' &安培; Challan& ','&买方& ','&风格与 ','&颜色和 ','&数量和数量 ')

cmdInsert.CommandType = CommandType.Text

cmdInsert.Connection = cnnOLEDB

cmdInsert.ExecuteNonQuery()
MessageBox.Show( 记录已插入
cmdInsert.Dispose()


如果 txtstyle.Text = zeera 然后

cmdUpdate.CommandText = UPDATE basic SET quantity ='& txtqty.Text& 'WHERE color =& black& ;

cmdUpdate.CommandType = CommandType.Text

cmdUpdate.Connection = cnnOLEDB

cmdUpdate.ExecuteNonQuery()

结束 如果

cmdUpdate.Dispose()
结束 Sub
结束

解决方案

您必须获取当前数量(SQL SELECT),添加新的添加内容,然后使用新数量更新记录(SQL UPDATE)。

Imports System.Data

Imports System.Data.OleDb
Public Class Form1
    Dim cnnOLEDB As New OleDb.OleDbConnection

    Dim cmdOLEDB As New OleDbCommand

    Dim cmdInsert As New OleDbCommand

    Dim cmdUpdate As New OleDbCommand

    Dim cmdDelete As New OleDbCommand

    Dim strConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=basic.accdb;Persist Security Info=False"

    Private Sub btnclear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnclear.Click
        txtchln.Text = ""
        txtbuyer.Text = ""
        txtstyle.Text = ""
        txtcolor.Text = ""
        txtqty.Text = ""

    End Sub

    Private Sub btnclose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnclose.Click
        Me.Close()

    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        cnnOLEDB.ConnectionString = strConnectionString
        cnnOLEDB.Open()

    End Sub

    Private Sub btnenter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnenter.Click
        Dim challan, buyer, style, color, qty
        challan = txtchln.Text
        buyer = txtbuyer.Text
        style = txtstyle.Text
        color = txtcolor.Text
        qty = txtqty.Text

        cmdInsert.CommandText = "insert into basic values('" & challan & "','" & buyer & "','" & style & "','" & color & "','" & qty & "')"

        cmdInsert.CommandType = CommandType.Text

        cmdInsert.Connection = cnnOLEDB

        cmdInsert.ExecuteNonQuery()
        MessageBox.Show("Records Inserted")
        cmdInsert.Dispose()


        If txtstyle.Text = "zeera" Then

            cmdUpdate.CommandText = "UPDATE basic SET quantity = '" & txtqty.Text & "' WHERE color = " & "black" & ";"

            cmdUpdate.CommandType = CommandType.Text

            cmdUpdate.Connection = cnnOLEDB

            cmdUpdate.ExecuteNonQuery()

        End If

        cmdUpdate.Dispose()
    End Sub
End Class

解决方案

You have to get the current quantity (SQL SELECT), add your new addition to it and then update the record with the new quantity (SQL UPDATE).


这篇关于如果再次输入样式,我们如何通过ms visual basic添加ms访问量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆