I have an application where in the textbox I insert a number and click on a button and it should add that value on a textbox that I've called "Balance". To make that happen I've used a query to sum the amount and display it where I want. But I at the moment I have some issues with casts.
This is the function that I am using to get the results and then make some if statements to validate it. I have this function on a class.
Public Function BalancoTotal()
SqlCon = New SqlConnection
SqlCon.ConnectionString = "........"
Query2 = "SELECT
CAST(SUM(amountTransaction) AS INT)
SqlCmd = New SqlCommand(Query2, SqlCon)
SqlDR = SqlCmd.ExecuteReader
If SqlDR.Read() Then
Catch ex As Exception
txtBalance.Text = callMethod.BalancoTotal()
txtBalance.Text = 0.00
txtBalance.Text = FormatCurrency(txtBalance.Text)
failed to convert parameter value from a string to a decimal
specified cast is not valid
txtBalance.Text = callMethod.BalancoTotal().ToString() txtBalance.Text = "0.00"
Event if it should cast it ...
For the other problem you should try:
.Add("@balaTransacao", SqlDbType.BigInt).Value = cint(txtBalance.Text)