tags:

views:

42

answers:

2

i have a table like this:

name code group

john 12
smith 15

how do i insert group for a specified row??

say for 'smith' i have to insert the group.. i tried d following:

INSERT INTO table (group) VALUES ('usher') where code =15

error: Incorrect syntax near the keyword 'where'.

please help!!

thanx in anicipation!!

+4  A: 
UPDATE  mytable
SET     group = 'usher'
WHERE   code = 15
Quassnoi
thanks bro!!but ma real problem isnt solved yet...actually want d user to enter code and group....in d form,he'll enter d code and d group....on proceeding, i want the group to be updated....so i used parametrized query:UPDATE table SET group='usher' WHERE code ='" + textBox2.Text + "' d program runs but no changes are reflected in the table...i hope u understood d problem...plz help
sry d query is wrong there...the actual query is:"UPDATE table SET group(@n) WHERE code ='" + textBox2.Text + "'"i doubt dis query as i m not sure of using d parameter 'n' bound with textbox2(d syntax)however,even d first query doesn't work.
Make sure you commit the transaction after the query completes.
Quassnoi
A: 

As mentioned in the previous answer you want to perform an UPDATE not an INSERT.

UPDATE is used to change existing rows while INSERT will create new rows. Hence why WHERE can not be used with an INSERT statement.

IllusivePro