0

这是我的编码部分...我想要的是当我单击按钮时,数据库中的值将被添加到文本框中。但是当我单击按钮时,我得到的是文本框中的值直接替换为数据库中的新值。有人可以帮我解决这个问题吗?

Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click

        txtShowDescrip.Text &= cmbDescrip.SelectedItem & ","

        Dim conn As OleDbConnection = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=SDP_DB.accdb")
        Dim str As String
        Dim dr As OleDbDataReader
        Dim cmd As OleDbCommand
        Dim total As Integer = 0
        conn.Open()
        str = "Select * From ChargeTable Where Description='" & cmbDescrip.Text & "'"

        cmd = New OleDbCommand(str, conn)
        dr = cmd.ExecuteReader
        dr.Read()
        If dr.HasRows = True Then

            total += dr.Item("PriceRate")
            txtShowRate.Text = "$" & total

        End If
        dr.Close()
        conn.Close()
    End Sub
4

4 回答 4

0

您可以使用静态声明..

Static total As Integer = 0

或者,如果您仍然使用Dim..

If dr.HasRows = True Then

    total = val(txtShowRate.Text) + dr.Item("PriceRate")
    txtShowRate.Text = "$" & format(total)

End If
于 2013-08-16T10:12:51.573 回答
0
If dr.HasRows = True Then
        total = CType(txtShowRate.Text,Integer) + dr.Item("PriceRate")
        txtShowRate.Text = "$" & total.ToString
End If
于 2013-08-16T09:07:52.527 回答
0

天哪,回读你自己的帖子;

...当我单击按钮时,文本框中的值将被添加到文本框中。但是当我单击按钮时,文本框中的值直接替换为新值。

那么,单击按钮时您究竟希望发生什么?

于 2013-08-16T06:40:28.087 回答
0

您当前将文本框的文本设置为新值,如果您想添加需要使用 & 或 &= 的新内容

    Dim nfi As New System.Globalization.NumberFormatInfo()
    nfi.CurrencySymbol = "$"

    dim tot as decimal = total + Decimal.Parse(TextBox1.Text, Globalization.NumberStyles.Any, nfi)


    txtShowRate.Text =  "$" & tot 
于 2013-08-16T07:00:05.620 回答