SQL Server 是否有更改调光函数值的代码

dsf9zpds  于 2023-01-20  发布在  其他
关注(0)|答案(1)|浏览(67)

我想通过www.example.com将数据放入SQL表中,分为Txn_AmountPost_Amount两列vb.net in two columns which are Txn_Amount and Post_Amount
其中textbox3 = Txn_Amount
过帐金额= Textbox4 - textbox3
但我希望如果textbox4 ="",则发布量应为0
这是我的代码:

Call Get_TxnID()
        
        Dim Txn_Amount As String = TextBox3.Text
          Dim Post_Amount As String = Val(TextBox4.Text) - Val(TextBox3.Text)
       

        Dim query As String = "Insert into Txn_Master values (@Txn_Amount,  @Post_Amount)"
        Using cmd As New SqlCommand(query, Connection)
            cmd.Parameters.AddWithValue("Txn_Amount", Txn_Amount)
            cmd.Parameters.AddWithValue("Post_Amount", Post_Amount)
            
            Connection.Open()
            cmd.ExecuteNonQuery()
            Connection.Close()

        End Using
        MsgBox("Transaction Success", MsgBoxStyle.Information)

当我在两个框中都有值时,它工作得很好。例如:-textbox3.text = 25000和textbox4.text = 50000,则Post_Amount为25000
但如果textbox3.text = 25000且textbox4.text ="",则post_amount中显示-25000,但如果textbox4 ="",则post金额应为""或"0"
我试过了

Dim Txn_Amount As String = TextBox3.Text
      If textbox4.text="" then
          Dim Post_Amount As String = ""
      Else
          Dim Post_Amount As String = Val(TextBox4.Text) - Val(TextBox3.Text)
      endif
       
        Dim query As String = "Insert into Txn_Master values (@Txn_Amount,  @Post_Amount)"
        Using cmd As New SqlCommand(query, Connection)

         
            cmd.Parameters.AddWithValue("Txn_Amount", Txn_Amount)
            cmd.Parameters.AddWithValue("Post_Amount", Post_Amount)
            
            Connection.Open()
            cmd.ExecuteNonQuery()
            Connection.Close()
        End Using
        MsgBox("Transaction Success", MsgBoxStyle.Information)

不过,现在可以用了,请帮我一下

wh6knrhe

wh6knrhe1#

Call Get_TxnID()
        
Dim Txn_Amount As String = TextBox3.Text
Dim Post_Amount As String

If TextBox4.Text = "" Then
    Post_Amount = DBNull.Value
Else
    Post_Amount = Val(TextBox4.Text) - Val(TextBox3.Text)
End If

Dim query As String = "Insert into Txn_Master values (@Txn_Amount,  @Post_Amount)"

Using cmd As New SqlCommand(query, Connection)
    cmd.Parameters.AddWithValue("Txn_Amount", Txn_Amount)
    cmd.Parameters.AddWithValue("Post_Amount", Post_Amount)

    Connection.Open()
    cmd.ExecuteNonQuery()
    Connection.Close()
End Using

MsgBox("Transaction Success", MsgBoxStyle.Information)

相关问题