Update pages with new widget?

Editor
Oct 2, 2012 at 5:04 PM

I need to update some of the pages and add a new widget, however I don't know how to run the SQL query

 

The table PageWidget has Id, sName wOrderID and pID. However I need to add a widget to pages in category C#, HTML, CSS and PHP. The order ID should be 10 and the sName should be pageInfo..

 

How can I do this?

 

Coordinator
Oct 2, 2012 at 7:50 PM

Not sure what is supported by sql ce, so that is why this solution:

first select pId of pages you want to update

select pId from rc_Pages
where pName='default' or pName='demo-skin-2'

of course in your case change "where" to your conditions

then loop thru returned records and run simple insert into for every record

 


Editor
Oct 2, 2012 at 11:16 PM
razorC wrote:

Not sure what is supported by sql ce, so that is why this solution:

first select pId of pages you want to update

select pId from rc_Pages
where pName='default' or pName='demo-skin-2'

of course in your case change "where" to your conditions

then loop thru returned records and run simple insert into for every record

 

This is what I got currently..

 

 

@{
   
   
 
 
   
   var db = Database.Open("razorc");
var sqlselect = "SELECT pid FROM rc_Pages WHERE pCategory='C#' or pCategory='VB'";
var data = db.Query(sqlselect);
 
 
var insert = "INSERT INTO rc_PageWidget (wId, sName, wOrderId, pId) VALUES ('38', 'rcPageInfo', '10', @0)";
 
 
db.Execute(insert);
 
 
}
 
 
<form method="post">
<select name="pId">
 
@foreach (var row in data){
    <option>@row.pid</option>
}
 
</select>
 
</form>
@{
   
   


   
   var db = Database.Open("razorc");
var sqlselect = "SELECT pid FROM rc_Pages WHERE pCategory='C#' or pCategory='VB'";
var data = db.Query(sqlselect);


var insert = "INSERT INTO rc_PageWidget (wId, sName, wOrderId, pId) VALUES ('38', 'rcPageInfo', '10', @0)";


db.Execute(insert);


}


<form method="post">
<select name="pId">

@foreach (var row in data){
    <option>@row.pid</option>
}

</select>


</form>

 

Does not work though, I don't know how to tell it to insert a row for each id in the select field..

Coordinator
Oct 3, 2012 at 1:58 AM
@{
    
var db = Database.Open("razorc");
var sqlselect = "SELECT pid FROM rc_Pages WHERE pCategory='C#' or pCategory='VB'";
var data = db.Query(sqlselect);

var insert = "INSERT INTO rc_PageWidget (wId, sName, wOrderId, pId) VALUES ('38', 'rcPageInfo', '10', @0)";

foreach (var row in data){
    db.Execute(insert,row.pId);
}


}

<!--CTYPE ht-->