C#/VB.NET Code:
<%
Set conn = Server.createobject("ADODB.CONNECTION")
Conn.open = "Driver={SQL Server};" & _
"Server=xxx.xxx.xxx;" & _
"Database=xxxx;" & _
"Uid=xxxxx;" & _
"Pwd=xxxx"
Dim SQL, pID1, pName1, pPrice1, pImg1, pID2, pName2, pPrice2, pImg2, pURL1, pURL2
Set rs = Server.CreateObject("ADODB.Recordset")
SQL = "SELECT TOP 2 p.*, pv.Price AS SalePrice FROM dbo.Product p with (nolock) left join dbo.productvariant pv with (NOLOCK) on p.ProductID = pv.ProductID left join dbo.ProductManufacturer pm with (NOLOCK) on p.ProductID = pm.ProductID "
SQL = SQL & " WHERE pm.ManufacturerID = 2 and p.Deleted = 0 and pv.Deleted = 0 and pv.Price > 0"
SQL = SQL & " ORDER BY NewID()"
rs.open SQL, conn
Dim rCount
rCount = 0
While Not rs.EOF
rCount = rCount + 1
'response.write(rs("ProductID") & " " & rs("SalePrice") & "<br /><br />")
if rCount =1 then
pName1 = rs("Name")
pID1 = rs("ProductID")
pImg1 = rs("ImageFilenameOverride")
pPrice1 = AddCommas(rs("SalePrice"))
pURL1 = "p-" & pID1 & "-" & replace(StripName(pName1)," ","-") & ".aspx"
else
pName2 = rs("Name")
pID2 = rs("ProductID")
pImg2 = rs("ImageFilenameOverride")
pPrice2 = AddCommas(rs("SalePrice"))
pURL2 = "p-" & pID2 & "-" & replace(StripName(pName2)," ","-") & ".aspx"
end if
rs.MoveNext
Wend
function AddCommas(price)
dim temp
if len(price) > 3 then
temp = "," & right(price,3)
temp = Left(price, len(price)-3) & temp
AddCommas = temp
else
AddCommas = price
end if
end function
function StripName(ProductName)
dim i
dim newString
dim validChars
validChars = "1234567890-qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM "
'Do while len(ProductName) > 0
' if instr(validChars, Left(ProductName,1)) > 0 then
' newString = newString & Left(ProductName,1)
' end if
'
' if len(ProductName) > 1 then
' ProductName = right(ProductName, len(ProductName) - 1)
' else
' ProductName = ""
' end if
'Loop
'
'StripName = newString
ProductName = Replace(ProductName,"(","")
ProductName = Replace(ProductName,")","")
ProductName = Replace(ProductName,"_","")
ProductName = Replace(ProductName,",","")
ProductName = Replace(ProductName,".","")
ProductName = Replace(ProductName,"|","")
ProductName = Replace(ProductName,"+","")
ProductName = Replace(ProductName,"=","")
ProductName = Replace(ProductName,";","")
ProductName = Replace(ProductName,":","")
ProductName = Replace(ProductName,"&","")
ProductName = Replace(ProductName,"/","")
ProductName = Replace(ProductName,"\","")
ProductName = Replace(ProductName,"[","")
ProductName = Replace(ProductName,"]","")
ProductName = Replace(ProductName,"{","")
ProductName = Replace(ProductName,"}","")
ProductName = Replace(ProductName,"*","")
ProductName = Replace(ProductName,"^","")
ProductName = Replace(ProductName,"%","")
ProductName = Replace(ProductName,"$","")
ProductName = Replace(ProductName,"#","")
ProductName = Replace(ProductName,"@","")
ProductName = Replace(ProductName,"!","")
ProductName = Replace(ProductName,"~","")
StripName = ProductName
end function
%>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Deals of the Week</title>
</head>
<body style="margin: 0 0 0 0; BACKGROUND-IMAGE: url(skins/skin_3/trimages/deals-background.jpg); BACKGROUND-COLOR: transparent">
<table id="tblMain" cellpadding="0" cellspacing="0" border="0" style="height: auto; width: auto;">
<tr>
<td valign="top" align="center" style="padding-top: 15px; padding-left: 3px; padding-right: 3px;">
<!-- product#1 -->
<div align="center"><a target="_parent" href="<%=pURL1 %>"><img width="150px" height="150px" src="images/Product/icon/<%=pID1 %>.jpg" style="border: groove 4; border-color:Maroon;"></a> </div>
<div align="center"><span style="FONT-SIZE: 8pt; FONT-FAMILY: Arial"><a target="_parent" href="<%=pURL1 %>"><%=pName1 %></a></span> </div>
<div align="center"><span style="FONT-SIZE: 8pt; FONT-FAMILY: Arial">Sale Price: $<%=pPrice1 %></span> </div>
<!-- end product #1 -->
<div align="center"> </div>
<!-- Product #2 -->
<div align="center"><a target="_parent" href="<%=pURL2 %>"><img width="150px" height="150px" src="images/Product/icon/<%=pID2 %>.jpg" style="border: groove 4; border-color:Maroon;"></a> </div>
<div align="center"><span style="FONT-SIZE: 8pt; FONT-FAMILY: Arial"><a target="_parent" href="<%=pURL2 %>"><%=pName2 %></a></span> </div>
<div align="center"><span style="FONT-SIZE: 8pt; FONT-FAMILY: Arial">Sale Price: $<%=pPrice2 %></span> </div>
<!-- end product #2 -->
</td>
</tr>
</table>
</body>
<%
rs.close
conn.close
Set rs = Nothing
Set conn = Nothing
%>
</html>