Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
i have following query:
INSERT INTO DSActor.DTL_PHOTOS(PUBLIC_SHARE,USER_SHARE,FRIEND_SHARE,PHOTO_TITLE,PHOTO_REMARK,PHOTO_STATUS)" + " VALUES (@PUBLIC_SHARE,@USER_SHARE,@FRIEND_SHARE,@PHOTO_TITLE,@PHOTO_REMARK,@PHOTO_STATUS WHERE DETAIL_ID='"+type_id+"')";
 
        cmd.Parameters.AddWithValue("@PUBLIC_SHARE", pub);
        cmd.Parameters.AddWithValue("@USER_SHARE", user);
        cmd.Parameters.AddWithValue("@FRIEND_SHARE", friend);
        cmd.Parameters.AddWithValue("@PHOTO_TITLE", photo_title);
        cmd.Parameters.AddWithValue("@PHOTO_REMARK", photo_remark);
        cmd.Parameters.AddWithValue("@PHOTO_STATUS", 1);
 
 
but it gives error near where clause.plz help me?
Posted 25-Nov-12 17:47pm
Edited 25-Nov-12 18:17pm
v2
Comments
dimpledevani at 25-Nov-12 23:52pm
   
insert cannot be used with where
Member 9027346 at 26-Nov-12 0:19am
   
yes,bt i want to add all details according to type id?
Bhushan Shah1988 at 26-Nov-12 0:08am
   
you cannot use where with INSERT.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

The answer is very simple.
 
You can not use a where clause with insert query. Why? Because an insert creates a new record and it will be created at the bottom of the table only.
 
If you wish to change some existing value use Update instead of Insert.
  Permalink  
v2
Comments
scottgp at 26-Nov-12 10:03am
   
"created at the bottom of the table only" doesn't make any sense
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

sinhasourabh says right ,you can't add where clouse in insert query ,becouse insert query add new record in database
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hi,
 
As everyone said, you can not use Where clause in Insert statement. but you want to add detail according to the type_id, so i suggest you to create one StoredProcedure.
 
This stored procedure will take the input and it will check for the Type_id in the database
1) if type_id record exist then update the record.
2) otherwise add new record with type_id.
 
Above case will apply only if your type_id is identity element.
 
Hope i answered your query.
  Permalink  
Comments
sinhasourabh at 26-Nov-12 23:56pm
   
I am not able to understand your answer completely. is it like this : if row_exists then ' run update else ' run insert
@AmitGajjar at 26-Nov-12 23:59pm
   
Yes because if you have identity value of type_id then you can not insert similar value in the table you can only do the update of the record. let me know if it is not clear.

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Shai Vashdi 1,588
1 OriginalGriff 528
2 Manas Bhardwaj 383
3 Damith Weerasinghe 330
4 Tadit Dash 315
0 Sergey Alexandrovich Kryukov 9,575
1 OriginalGriff 6,006
2 Peter Leow 4,500
3 Maciej Los 3,540
4 Abhinav S 3,513


Advertise | Privacy | Mobile
Web04 | 2.8.140415.2 | Last Updated 26 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid