Mysql
 sql >> Datenbank >  >> RDS >> Mysql

Ich erhalte eine Fehlermeldung Fehler beim Konvertieren des Datentyps nvarchar in real.

Da Sie @Price keinen Wert zuweisen im C#-Code während Ihre Warehouse Id und den Discount rate vom Endbenutzer zugewiesen werden müssen, empfehle ich Ihren Code wie folgt:

   private void button4_Click(object sender, EventArgs e)
   {​​​​​​​
        try
        {​​​​​​​
            var discountRate = 0.07; //could be Convert.ToDouble(textBox1.Text) or something else
            var warehouseId = 6;    //again, could be Convert.ToInt32(textBox2.Text) or something else
            myConnection = new SqlConnection(frm.cs);
            myCommand = new SqlCommand("update Inventory set Price=Price*(example@sqldat.com) " +
                                        "where example@sqldat.com", myConnection);
            myConnection.Open();
            myCommand.Parameters.AddWithValue("@DiscountRate", discountRate);
            myCommand.Parameters.AddWithValue("@WarehouseId", warehouseId);
            myCommand.ExecuteNonQuery();
            myConnection.Close();
            MessageBox.Show("Update successfully!");
            DisplayData();
            if (myConnection.State == ConnectionState.Open)
            {​​​​​​​
               myConnection.Dispose();
            }​​​​​​​
        }
        catch
        {

        }
    }​​​​​​​

Ich würde Ihnen auch empfehlen, Ihre Abfrage noch einmal zu überdenken, da alle Produktpreise mit demselben Wert aktualisiert werden. Sie können den Parameter @ProductId übergeben und Ihre Anfrage lautet

update Inventory set Price=Price*(example@sqldat.com) 
where example@sqldat.com and example@sqldat.com

Sicher war das zum Beispiel.