Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
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 23-Jan-13 1:33am
Edited 23-Jan-13 2:01am
v3
Comments
Faisalabadians at 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
good
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>)
Else
    Update <tablename> Set value=<value> where userid=2
  Permalink  
v2
Rate this: bad
good
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...
}
  Permalink  
Comments
digimanus at 23-Jan-13 9:47am
   
or db.User.Any(x =>x.UserID == 2);
 
but my 5
shiny13 at 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
0 Sergey Alexandrovich Kryukov 547
1 ChauhanAjay 180
2 CHill60 135
3 Maciej Los 125
4 Richard Deeming 125
0 Sergey Alexandrovich Kryukov 9,735
1 OriginalGriff 6,987
2 CPallini 5,835
3 George Jonsson 4,017
4 Gihan Liyanage 3,266


Advertise | Privacy | Mobile
Web03 | 2.8.140926.1 | Last Updated 23 Jan 2013
Copyright © CodeProject, 1999-2014
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