每当您按此按钮在datagridview中添加1个数量时,如何更改此代码? [英] How can I change this code to do that whenever you press this button to add 1 qty in datagridview ?

查看:113
本文介绍了每当您按此按钮在datagridview中添加1个数量时,如何更改此代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 Private Sub OK_Click(ByVal sender As System。 Object ,ByVal e As System.EventArgs)处理btnAdd.Click 

Dim sqlQRY As String = SELECT * FROM产品WHERE ProductCode ='& txtCode.Text& '
Dim cmd As OleDbCommand = New OleDbCommand(sqlQRY,conn)
Dim rdr As OleDbDataReader = cmd.ExecuteReader

如果txtCode.Text = 然后
MessageBox.Show( 输入产品代码! 警告!,MessageBoxButtons.OK,MessageBoxIcon.Exclamation)
txtCode.Text =
txtCode.Focus()
ElseIf rdr.HasRows然后
rdr。 Read()

Dim intProductID As Integer = rdr( ProductID) .ToString

Dim newRow As SalesDataSet.SalesDetailsRow = SalesDataSet.SalesDetails.NewSalesDetailsRow

newRow.SalesID = SalesIDTextBox.Text
newRow.ProductName = intProductID
newRow.Qty = 1
Dim Price As Decimal = rdr( 价格
newRow.Price =价格
newRow.Amount =价格

SalesDataSet.SalesDetails.Rows.Add(newRow)

txtCode.Text =
txtCode.Focus()
否则
MessageBox.Show( 找不到产品! 警告!, MessageBoxButtons.OK,MessageBoxIcon.Exclamation)
txtCode.Text =
txtCode.Focus()
结束如果

txtTotal.Text = Totals()

Dim vat As Deci mal

vat = Val(txtTotal.Text)* 0 12

txtVAT.Text = vat
Button1.Enabled = True

End Sub





我尝试过:



我试图将newRow.Qty = 1更改为newRow.Qty + = 1但不工作!



请帮我这个代码。谢谢 ! :)

解决方案

我可以看到你的代码在哪里进行读取而不是写入,你没有代码以任何方式向数据库提交更新。你有阅读器部分,你需要编写器部分即保存或更新。



您需要类似这样的代码,虽然不是完美的,但却能为您提供正确的代码。



 Private Sub save_Click(sender As Object,e As EventArgs)处理save.Click 
sqlQRY =Insert intodatabase (数量)值('& Qty.Text&')/或数据网格的单元格
Dim cmd As New OleDbCommand(sqlQRY,conn)


Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
 
    Dim sqlQRY As String = "SELECT * FROM Products WHERE ProductCode = '" & txtCode.Text & "'"
    Dim cmd As OleDbCommand = New OleDbCommand(sqlQRY, conn)
    Dim rdr As OleDbDataReader = cmd.ExecuteReader
 
    If txtCode.Text = "" Then
        MessageBox.Show("Input a product code!", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        txtCode.Text = ""
        txtCode.Focus()
    ElseIf rdr.HasRows Then
        rdr.Read()
 
        Dim intProductID As Integer = rdr("ProductID").ToString
 
        Dim newRow As SalesDataSet.SalesDetailsRow = SalesDataSet.SalesDetails.NewSalesDetailsRow
 
        newRow.SalesID = SalesIDTextBox.Text
        newRow.ProductName = intProductID
        newRow.Qty = 1
        Dim Price As Decimal = rdr("Price")
        newRow.Price = Price
        newRow.Amount = Price
 
        SalesDataSet.SalesDetails.Rows.Add(newRow)
 
        txtCode.Text = ""
        txtCode.Focus()
    Else
        MessageBox.Show("Product not found!", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        txtCode.Text = ""
        txtCode.Focus()
    End If
 
    txtTotal.Text = Totals()
 
    Dim vat As Decimal
 
    vat = Val(txtTotal.Text) * 0.12
 
    txtVAT.Text = vat
    Button1.Enabled = True

End Sub



What I have tried:

I tried to to change " newRow.Qty = 1 " to " newRow.Qty += 1 " but not working!

Please help me for this code. Thanks ! :)

解决方案

i can see where your code is making a read but not a write, you have no code submitting an update to your database in any fashion. you have the reader portion you need the writer portion aka save or update.

you would need something like this code, not perfect though gives you the just of it.

Private Sub save_Click(sender As Object, e As EventArgs) Handles save.Click
        sqlQRY = "Insert into " database" (Qty) values ('" & Qty.Text & "')"     /'or your cell of the datagrid
        Dim cmd As New OleDbCommand(sqlQRY, conn)


这篇关于每当您按此按钮在datagridview中添加1个数量时,如何更改此代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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