I'm getting an error
incorrect syntax near the keyword WHERE
with the following SQL statement:
SqlCommand scInsertCostSpilt = new SqlCommand("INSERT INTO [ASSETS_CC] ([DEPT], [CC], [PER_CENT]) WHERE [ASSET_NO] = @AssetNumber)" +
"Values (@AssetNumber, @Dept, @CC, @PerCent)" , DataAccess.AssetConnection);
What's wrong?
In SQL insert statements do not have a WHERE
clause (which makes sense, because the record is not there yet). You put the IDs together with all other values if you would like to insert a new record, or use an UPDATE
statement if you would like to change an existing record.
INSERT INTO [ASSETS_CC] ([ASSET_NO], [DEPT], [CC], [PER_CENT])
VALUES (@AssetNumber, @Dept, @CC, @PerCent)
or
UPDATE [ASSETS_CC]
SET [DEPT] = @Dept, [CC] = @CC, [PER_CENT] = @PerCent
WHERE [ASSET_NO] = @AssetNumber
I think you have written wrong query. Update as below given query:
INSERT INTO [ASSETS_CC] ([DEPT], [CC], [PER_CENT]) Values ( @Dept, @CC, @PerCent)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With