質問

i have a combobox populated with data :

Beef
Calamansi
Chicken
Egg
Fish
Fish_Sauce
Oil
Pork
Rice
Soy_Sauce
Vegetables
Vinegar

then if choose the Beef in my comboBox then press a button it will search my database Stocks_Name for Beef then in my textbox1 i will input an integer then add that to Total_Stocks equivalent to Beef data. enter image description here

what commandtext should i use because i cant find a specific commandtext in the internet for my problem. i only know how to insert and select. thank you in advance :D

UPDATE:

it didn't add but instead it changed my data 100 to 1 it should be 101. here is my work: `

connection.Open();

OleDbCommand cmd = new OleDbCommand(@"UPDATE Add_Stocks SET Total_Stocks=@QWE WHERE Stocks_Name=@STOCKS" , connection);
cmd.Parameters.AddWithValue("@QWE", textBox1.Text);
cmd.Parameters.AddWithValue("@STOCKS", comboBox1.Text);


cmd.ExecuteNonQuery();
{
    MessageBox.Show("ADDED!");
    connection.Close();
}
役に立ちましたか?

解決

You'll need the UPDATE-Statement which

creates an update query that changes values in fields in a specified table based on specified criteria.

Syntax:

UPDATE Your_Table_Name
SET Total_Stocks = Total_Stocks + @IncrementValue, 
WHERE Stocks_Name = 'Beef';

You'll need to add an Parameter to fill @IncrementValue

yourOleDBCommand.Parameters.Add("@IncrementValue", OleDbType.Integer).Value = Convert.ToInt32(yourTextBox.Text);

Source: MSDN

他のヒント

if i understood your question their is simple query,

UPDATE Your_Table_Name 
SET Total_Stocks = Total_Stocks + @Int_Value_from_Textbox
WHERE Stock_Name = 'Beef'

where @Int_Value_from_Textbox is the parameter that u need to add to your command before executing.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top