Amount Update Issue RRS feed

  • Question

  • User-527908287 posted

    i tried to effect an update on user wallet table and got an error https://imgur.com/VALYBXA

    I have a UserWallet table which this update will take place after fetching an existing record and adding the new amount to it and update. these update will be done after receiving response from payment gateway on successful payment

    client.AddDefaultHeader("Authorization", "Bearer sk_test_065xxxxxxxxxxxxxxxxxxxxxxxx");
            IRestResponse response = client.Execute(request);
            if (response.IsSuccessful)
                var jsonResponse = response.Content;
                var verificationResponse = JsonConvert.DeserializeObject<PaymentResponse>(jsonResponse);
                if (verificationResponse.status && verificationResponse.data.status == "success")
                    var amountPaid = (verificationResponse.data.amount / 100);
                    var customerEmail = verificationResponse.data.customer.email;
                    UpdateWallet(customerEmail, amountPaid);
                    //write your update query here.......
        private void UpdateWallet(string email, decimal amount)
            SqlConnection conn = new SqlConnection("Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\\Dataregister.mdf;Integrated Security=True");
            string query = "SELECT Amount FROM UserWallet where Email = @email", con;
            var cmd = new SqlCommand(query, conn);
            SqlDataReader reader = cmd.ExecuteReader();
            var Amount = reader["Amount"].ToString() + @amount;
            string strSql = "update UserWallet set Amount ='" + amount + "' where Email = @email ";
            SqlCommand cmd2 = new SqlCommand(strSql, conn);
            cmd2.Parameters.AddWithValue("@amount", amount);

    from the top of the code is where the payment response comes in JsonResponse and in the yellow highlighted area is my c# code to effect updates of thie megnitude.

    Tuesday, June 9, 2020 9:44 PM

All replies

  • User-943250815 posted

    Seems the answer is on error screen "Must declare scalar variable @email"

    Just a guess, try change


    string query = "SELECT Amount FROM UserWallet where Email = @email"


    string query = "SELECT Amount FROM UserWallet where Email = " + email

    Tuesday, June 9, 2020 10:16 PM
  • User1535942433 posted

    Hi Donald416,

    As far as I think,you need to add AddWithValue of email like this:

     cmd2.Parameters.AddWithValue("@email", email);

    Best regards,

    Yijing Sun

    Wednesday, June 10, 2020 6:08 AM