Click here to Skip to main content
15,896,606 members
Home / Discussions / C#
   

C#

 
AnswerRe: Problem with SQLDataReader and Insert command PinPopular
Luc Pattyn20-Nov-11 9:50
sitebuilderLuc Pattyn20-Nov-11 9:50 
GeneralRe: Problem with SQLDataReader and Insert command Pin
CCodeNewbie20-Nov-11 12:04
CCodeNewbie20-Nov-11 12:04 
AnswerRe: Problem with SQLDataReader and Insert command Pin
Luc Pattyn20-Nov-11 12:19
sitebuilderLuc Pattyn20-Nov-11 12:19 
GeneralRe: Problem with SQLDataReader and Insert command Pin
PIEBALDconsult21-Nov-11 4:55
mvePIEBALDconsult21-Nov-11 4:55 
GeneralRe: Problem with SQLDataReader and Insert command Pin
CCodeNewbie21-Nov-11 8:09
CCodeNewbie21-Nov-11 8:09 
GeneralRe: Problem with SQLDataReader and Insert command Pin
Pete O'Hanlon22-Nov-11 0:37
mvePete O'Hanlon22-Nov-11 0:37 
GeneralRe: Problem with SQLDataReader and Insert command Pin
CCodeNewbie22-Nov-11 1:13
CCodeNewbie22-Nov-11 1:13 
GeneralRe: Problem with SQLDataReader and Insert command Pin
Pete O'Hanlon22-Nov-11 3:03
mvePete O'Hanlon22-Nov-11 3:03 
That's fine. I should have also mentioned how you would do this - I'm assuming you are using SQL Server 2008 here, which allows you to do something called an UPSERT command. Basically, that's an INSERT and UPDATE command all rolled into one (although you can just use the INSERT part on its own).

The syntax you would use is
SQL
MERGE sometable
USING (select something FROM table) ON (value = @value)
WHEN NOT MATCHED THEN INSERT VALUES (...)

Forgive your enemies - it messes with their heads

"Mind bleach! Send me mind bleach!" - Nagy Vilmos


My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility


GeneralRe: Problem with SQLDataReader and Insert command Pin
CCodeNewbie22-Nov-11 9:50
CCodeNewbie22-Nov-11 9:50 
GeneralRe: Problem with SQLDataReader and Insert command Pin
Pete O'Hanlon22-Nov-11 10:20
mvePete O'Hanlon22-Nov-11 10:20 
GeneralRe: Problem with SQLDataReader and Insert command Pin
CCodeNewbie22-Nov-11 11:43
CCodeNewbie22-Nov-11 11:43 
GeneralRe: Problem with SQLDataReader and Insert command Pin
Pete O'Hanlon22-Nov-11 22:51
mvePete O'Hanlon22-Nov-11 22:51 
GeneralRe: Problem with SQLDataReader and Insert command Pin
CCodeNewbie22-Nov-11 23:06
CCodeNewbie22-Nov-11 23:06 
GeneralRe: Problem with SQLDataReader and Insert command Pin
Pete O'Hanlon23-Nov-11 0:53
mvePete O'Hanlon23-Nov-11 0:53 
GeneralRe: Problem with SQLDataReader and Insert command Pin
CCodeNewbie23-Nov-11 1:12
CCodeNewbie23-Nov-11 1:12 
GeneralRe: Problem with SQLDataReader and Insert command Pin
Pete O'Hanlon23-Nov-11 1:22
mvePete O'Hanlon23-Nov-11 1:22 
GeneralRe: Problem with SQLDataReader and Insert command Pin
CCodeNewbie23-Nov-11 10:19
CCodeNewbie23-Nov-11 10:19 
GeneralRe: Problem with SQLDataReader and Insert command Pin
Pete O'Hanlon23-Nov-11 23:44
mvePete O'Hanlon23-Nov-11 23:44 
GeneralRe: Problem with SQLDataReader and Insert command Pin
CCodeNewbie24-Nov-11 9:55
CCodeNewbie24-Nov-11 9:55 
GeneralRe: Problem with SQLDataReader and Insert command Pin
Pete O'Hanlon24-Nov-11 22:30
mvePete O'Hanlon24-Nov-11 22:30 
GeneralRe: Problem with SQLDataReader and Insert command Pin
CCodeNewbie24-Nov-11 22:32
CCodeNewbie24-Nov-11 22:32 
GeneralRe: Problem with SQLDataReader and Insert command Pin
Pete O'Hanlon24-Nov-11 22:48
mvePete O'Hanlon24-Nov-11 22:48 
GeneralRe: Problem with SQLDataReader and Insert command Pin
CCodeNewbie24-Nov-11 22:51
CCodeNewbie24-Nov-11 22:51 
GeneralRe: Problem with SQLDataReader and Insert command Pin
CCodeNewbie25-Nov-11 10:51
CCodeNewbie25-Nov-11 10:51 
GeneralRe: Problem with SQLDataReader and Insert command Pin
Pete O'Hanlon30-Nov-11 5:34
mvePete O'Hanlon30-Nov-11 5:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.