0

Below is my code:

@{

    Layout = "/_SiteLayout.cshtml";
    var db = Database.Open("MyDatabase");

    var query = "SELECT * FROM Team";
    var Teams = db.Query(query);
 }

    <form>
        <table>
        <tr>
            <td>Team Name</td>
            <td>Played</td>
            <td>Points</td>
        </tr>
  @{  foreach(var Team in Teams){
        <tr>
            <td>@Team.TeamName</td>
            <td><input type="text" value="@Team.Played" name="Played"/></td>
            <td><input type="text" value="@Team.Points" name="Points"/></td>
        </tr>
    }    
   }        
        </table>
    </form>

This is the result:

enter image description here

So what I want to do is update my whole table.

What is the SQL query to do this? I want to update Points and Games Played in my database for all teams once the form is posted.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Dawood Awan
  • 7,051
  • 10
  • 56
  • 119

2 Answers2

0

I don't actually understand what exactly you are trying to achieve (update your whole table with what?), but here is some information you might find useful:

SQL Update Tutorial, SQL Update, Update from Select

Community
  • 1
  • 1
Sam
  • 1,564
  • 4
  • 23
  • 37
  • I want to update the rows. for example A user changes Points for Arsenal then the Database should update that for Arsenal. similarly if the user updates all rows then the script should update all rows. So as i do this: var string = Request[Team.Points] it is the same for all. I need a unique value to Request["HERE"] – Dawood Awan Jan 05 '13 at 18:16
0

Following is My Solution. Anyone have an efficient Solution?

@{

var db = Database.Open("MYDATABSE");

var query = "SELECT * FROM Team";
var Teams = db.Query(query);
var InsertQuery = "";
if(IsPost){

   foreach(var Team in Teams){
       var Points = Request[Team.TeamName];
       var TeamId = Team.TeamId.ToString();
       var Played = Request[TeamId];

       var executeQueryString="UPDATE Team Set Points=@0, Played=@1 WHERE TeamId=@2";
       db.Execute(executeQueryString, Points, Played, Team.TeamId);

   }
   Response.Redirect("~/UpdateTable.cshtml");

}

}

<br /><br />


 <form  action="" method="post">
        <table>
        <tr>
            <td><h5>Team Name</h5></td>
            <td><h5>Played</h5></td>
            <td><h5>Points</h5></td>
        </tr>
  @{  foreach(var Team in Teams){
        <tr>
            <td>@Team.TeamName</td>
            <td><input type="text" value="@Team.Played" name="@Team.TeamId"/></td>
            <td><input type="text" value="@Team.Points" name="@Team.TeamName"/></td>
        </tr>
    }    
   }     
Dawood Awan
  • 7,051
  • 10
  • 56
  • 119