Microsoft
Software
Hardware
Network
Question : SQL CE Insert If Data Doesn't Exist
Hello Experts,
I'm writing a C# application and using SQL Server Compact Edition as a local database, as I'm unable to write stored procedures for it (I'm assuming that's correct!) I need to somehow write a query that will insert data, but only if it doesn't currently exist in the table.
I have a query that goes:
string insert = "INSERT INTO myTable (Column1, Column2, Column3) VALUES (Data1, Data2, Data3)
I tried putting WHERE NOT EXISTS(SELECT * FROM myTable WHERE Column1 = Data1), but I get the following error:
There was an error parsing the query. [ Token line number = 1,Token line offset = 399,Token in error = WHERE ]
What is the correct way to only insert if the data doesn't currently exist?
Answer : SQL CE Insert If Data Doesn't Exist
instead of the insert into (...) values(...)
format
use
INSERT INTO myTable (Column1, Column2, Column3)
select @var1,@var2,@var3
WHERE NOT EXISTS (SELECT * FROM myTable WHERE Column1 = @var1)
you don't need a from clause...
Random Solutions
Joomla 1.0.11 with VirtueMart 1.0.7 - to be upgraded to Joomla 1.5 with VirtueMart 1.1.4
Can't hide GridView Delete button programmatically -- help!
Outlook 2007 and 2 exchaneg servers
cannot log you in because the domain is not available WORKAROUND?
How to preform Multi Thread Join Async
Saving 3ds Max 2009 files taking ages !!
How to make hp nx7300 start?
I removed the cmos battery from a dell power edge 2650
On a File/Print server, is there a way to tell who has certain printers mapped?
SBS 2003 migration to new hardware