Alternative of PHP "Unset" function is ASP

F

fasanay

Hi everybody I have got the following PHP code which I am trying to convert to
ASP any help will be appreciated...I have done most of it but I cant find a
replace function for Unset in asp which will discard the variable alltogether...


if ($categoryid == "all")
{
$sql = "SELECT * FROM products where shopinspection=$shopinspection";
unset($HTTP_POST_VARS['categoryid']);
unset($HTTP_POST_VARS['shopinspection']);
}
else
{
$sql = "SELECT * FROM products where categoryid = $categoryid";
unset($HTTP_POST_VARS['categoryid']);
}
unset($HTTP_POST_VARS['Submit']);
while (list($key, $value) = each($HTTP_POST_VARS))
{
if ($value != "" )
{
$sql = $sql .=" AND $key=$value";
//$sql = $sql .=" AND solesource = $solesource";
//echo "<strong>$value</strong>";
}
}
 
W

WALDO

I don't believe there is a .Net equivalent of what you're looking for.
This is off the top of my head, so excuse me if there's any flaws. I
also didn't know what language you were trying to write this in. This
should accoumplish what you're looking to do.

[VB.Net]
Dim postVars As New Specialized.NameValueCollection(Request.Form)

If strCategory = "all" Then
strSQL = "SELECT * FROM products where shopinspection=" &
strShopInspection
postVars.Remove("categoryid")
postVars.Remove("shopinspection")
Else
strSQL = "SELECT * FROM products where categoryid = " & strCategoryId
postVars.Remove("categoryid")
End If

postVars.Remove("Submit")
Dim strKey As String
Dim strValue As String
For Each strKey In postVars.Keys
strValue = postVars.Item(strKey)
If (strValue <> "") Then
strSQL &= " AND " & strKey & "=" & strValue
End If
Next

[C#]
Specialized.NameValueCollection postVars = new
Specialized.NameValueCollection(Request.Form);

if (strCategory == "all")
{
strSQL = "SELECT * FROM products where shopinspection=" +
strShopInspection;
postVars.Remove("categoryid");
postVars.Remove("shopinspection");
} else {
strSQL = "SELECT * FROM products where categoryid = " + strCategoryId;
postVars.Remove("categoryid");
}

postVars.Remove("Submit");
String strKey;
String strValue;
foreach (strKey in postVars.Keys)
{
strValue = postVars.Item(strKey);
if (strValue != "")
{
strSQL += " AND " + strKey + "=" + strValue;
}
}




Sometimes the greatest solutions come from the simplest logic.
Being told no is merely the incentive to do it anyway.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top