Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

SQL CE Insert If Data Doesn't Exist

Avatar of angus_young_acdc
angus_young_acdcFlag for United Kingdom of Great Britain and Northern Ireland asked on
DatabasesC#Microsoft SQL Server 2008
11 Comments1 Solution2651 ViewsLast Modified:
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?
ASKER CERTIFIED SOLUTION
Avatar of Lowfatspread
Commented:
This problem has been solved!
Unlock 1 Answer and 11 Comments.
See Answers