我想通过www.example.com将数据放入SQL表中,分为Txn_Amount
和Post_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)
不过,现在可以用了,请帮我一下
1条答案
按热度按时间wh6knrhe1#