Start New Discussion within our Software Development Community

Ummm hi,
Ive been having some problems with a program ive been working on. I want to insert a new value in a column in a table from a calculation i get and replace the original value. Heres the part of the code:

private void button11_Click(object sender, EventArgs e)
{
if ((Convert.ToInt16(textBox6.Text)) > (Convert.ToInt16(comboBox4.Text)))
{
MessageBox.Show("Not enough!");
}
else if ((Convert.ToInt16(textBox6.Text)) < (Convert.ToInt16(comboBox4.Text)))
{
textBox8.Text = Convert.ToString(Convert.ToInt16(comboBox4.Text) - Convert.ToInt16(textBox6.Text));
MessageBox.Show("Amount removed!");
}



CHANNEL = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Database1.accdb;Persist Security Info=False;"); // database code
string key = "insert into item (Amount Left)values(@Amount Left) where ID = 4";   //key


COMMAND = new OleDbCommand(key, CHANNEL);



COMMAND.Parameters.Add(new OleDbParameter("@Amount Left", OleDbType.BSTR));   //insert into ID whats in ID field whats in text box5
COMMAND.Parameters["@Amount Left"].Value = textBox8.Text;


textBox6.Text = "";
textBox8.Text = "";
}

I have a text box 8, where the result of the calculation is stored. And i want to replace or "update" the current value in the column "Amount Left" in the table "Item" with te value i have in TextBox8. How can I do this? Thank you ;)

For a start you are using INSERT when you say you want to UPDATE. Insert puts a new row in the database table whereas UPDATE finds the current value and replaces it.
And you don't seem to be calling the command on the database at all either. Yo haven't posted up a COMMAND.executeNonQuery() at any rate.

This article has been dead for over six months. Start a new discussion instead.