Click here to Skip to main content
13,000,017 members (48,282 online)
Rate this:
Please Sign up or sign in to vote.
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.

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 23-Jan-13 1:33am
Updated 23-Jan-13 2:01am
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?
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

If you want to insert record based on some condition:

If Not Exists(Select * From <tablename> where <filter expression>)
    Insert Into <tablename>(<coulmns>) Values(<values>)
    Update <tablename> Set value=<value> where userid=2
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Try to use LINQ query and find the row like this if you are using entity framework:

var db = new DataContext();
var user = db.User.Where(x => x.UserId == 2)
if(user != null)
    //Your code here...
digimanus 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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170624.1 | Last Updated 23 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100