c# - Button for updating database not working -
i have database tables
dbo.auctions:[id][productid][lastbider][bidvalue][lastbid]dbo.products:[id][name]dbo.users:[id][name][password][bids]
i need write procedure checks if [bids] more 0.
if is, [lastbid] updated , [bidvalue] added it, lastbid = lastbid + bidvalue, , [bids] lowered 1, bids = bids - 1. , need connect button in visual studio.
i wrote procedure:
alter procedure [dbo].[usp_makebid] ( @userid int, @auctionid int ) declare @bids int, @lastbid int select @bids = count (*) users users.id = @userid if @bids > 0 begin update auctions set lastbid = @lastbid + bidvalue id = @auctionid , lastbid = @lastbid update users set bids = @bids - 1 bids = @bids end and connected button :
protected void button1_click(object sender, eventargs e) { using (var con = new sqlconnection(@"data source=jovan-pc;database=aukcija_jovan_gajic;integrated security=true")) { con.open(); var userid = 1; var auctionid = 2; var cmd = new sqlcommand("usp_makebid", con); cmd.parameters.addwithvalue("@userid", userid); cmd.parameters.addwithvalue("@auctionid", auctionid); cmd.commandtype = commandtype.storedprocedure; cmd.executenonquery(); con.close(); } } but when click on button, nothing happens.
main page looks this, maybe can give general idea :
pass values userid , auctionid update table..
example :
int userid = 456789; int auctionid = 12345; cmd.parameters.addwithvalue("@userid", sqldbtype.int).value = userid; cmd.parameters.addwithvalue("@auctionid", sqldbtype.int).value = auctionid; 
Comments
Post a Comment