Thursday, 15 January 2015

sql server - updater content to ++ 1 in the database - C# -



sql server - updater content to ++ 1 in the database - C# -

it such must have built such when kommmer articles sends database +1 each time load page,

i have done this:

int id = convert.toint32(request.querystring["id"]); string viewset = "1"; sqlconnection conn = new sqlconnection(configurationmanager.connectionstrings["connectionstring"].tostring()); sqlcommand cmd = new sqlcommand(); cmd.connection = conn; cmd.commandtext = "update artikler set viewset = @viewset++1 id = @id;"; cmd.parameters.addwithvalue("@id", id); cmd.parameters.addwithvalue("@viewset", viewset); conn.open(); cmd.executenonquery(); conn.close();

comes nil database

update artikler set viewset = isnull(viewset + 1, 1) id = @id

set initial viewset if null 1, otherwise increment it. don't need pass parameter. (unless trying set initial value other 1?)

c# sql-server ado.net

No comments:

Post a Comment