954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

C# Update Access Database Problem

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 ;)

toki93
Newbie Poster
1 post since Oct 2011
Reputation Points: 10
Solved Threads: 0
 

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.

hericles
Practically a Posting Shark
823 posts since Nov 2007
Reputation Points: 136
Solved Threads: 166
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: