lundi 28 septembre 2015

Webmatrix How to update database based on individual result from dynamic checkbox

I am pretty new to programming, but I have decided to start by creating a small app to have fun with my friends.

Basically, I have a webpage that allows me to add users to my database. I have another page that should allow me to select active members and update their "Active" field in my database.

My problem is that the result of the checkbox is giving me the list of the selected members separated with a comma, but does not give me each member separately so that I can update their field once they are selected.

My code looks like this

@{

var db= Database.Open("RaidGuru");
var sqlQ = "SELECT * FROM RaidMembers";
var data = db.Query(sqlQ);
var RaidMember = Request["RaidMember"];

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>Select your Raid !</title>
    <link href="Style.css" rel="stylesheet">
</head>
<body>

    <nav id="nav01"></nav>

<form action="" method="post"> 
    <fieldset>
        <legend>Sample Form <input type="button" value="Reload" onClick="parent.location='SelectRaid.cshtml'"></legend>

        <p>Select the RaidMembers in your Raid tonight !:

            @foreach(var row in data){    
        <p><input type="checkbox" name="RaidMember" value="@row.RaidMember" > @row.RaidMember, @row.RaidPoints</p>                        
                                     }

        <p><input type="submit" value="Proceed">
    </fieldset>
</form>

<script src="Navigation.js"></script>

</body>
</html>

 if(IsPost)
{
        if(RaidMember != null)
        {   <text>
            <fieldset>
            <legend>Sample Result</legend>
            <p>Your RaidMembers tonight : @RaidMember
            </fieldset>
            </text>



        var updateQueryString = "UPDATE RaidMembers SET RaidingNow=@0 WHERE RaidMember=@1" ; 
        RaidMember = @RaidMember;
        db.Execute(updateQueryString,1, RaidMember); 



        }    
 }
}

It does not update the RaidingNow field in my database because @Raidmember Returns "Raider1,Raider2,Raider3" instead of Returning "Raider1" then "Raider2" then "Raider3", etc...

I would gladly appreciate some help to be able to move forward.

Thanks a lot,

Best Regards




Aucun commentaire:

Enregistrer un commentaire