Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
3.00/5 (3 votes)
See more:
i have to insert data into user table where userid=2 .but insert query not allow where condition.So what is solution for that.

i have user table.
name
address
email
count1
count2
count3

when i submit data record inserted into table with value name,address,email.
then second page open and three PDF file are there with three view button.
when i click on button one count1 is incremented.when i click on button two count2 is incremented.when i click on button three count3 is incremented.

there for i have to insert this count information in table where userid=2
Posted
Updated 23-Jan-13 2:01am
v3
Comments
Faisalabadians 23-Jan-13 7:41am    
you question is not making any meaning full thing, can you explain it more with your code (if you have any). are you trying to update an existing record where userid=2? also tell me is this a primary key?

If you want to insert record based on some condition:

SQL
If Not Exists(Select * From <tablename> where <filter expression>)
    Insert Into <tablename>(<coulmns>) Values(<values>)
Else
    Update <tablename> Set value=<value> where userid=2
 
Share this answer
 
v2
Try to use LINQ query and find the row like this if you are using entity framework:

C#
var db = new DataContext();
var user = db.User.Where(x => x.UserId == 2)

if(user != null)
{
    //Your code here...
}
 
Share this answer
 
Comments
Herman<T>.Instance 23-Jan-13 9:47am    
or db.User.Any(x =>x.UserID == 2);

but my 5
shiny13 23-Jan-13 10:00am    
Glad I could help :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900