Solved

asp to asp.net / vb.net

Posted on 2011-09-09
1
378 Views
Last Modified: 2012-06-27
Have the attached codes working in classic.asp and now like to convert to asp.net/ vb.net
Any experts who can help will be very helpful.

500 points for completing working codes.

Thanks,
<%@LANGUAGE="Vbscript" CODEPAGE="65001"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
<body>
<% 
Category="COOLANT"
Function TotalRecordCount(Category)
SQL=" Select Top 1 PartNo, "
SQL=SQL & " Row_Number() Over(Order By PartNo) rownumber, "
SQL=SQL & " Count(*) Over() as TotalRecordCount "
SQL=SQL & " From Products "
SQL=SQL & " where Category = '" & Category & "' "
SQL=SQL & " Order By partno asc "
set dbsecurecon  = Server.CreateObject("ADODB.Connection")
dbsecurecon = "PROVIDER=SQLOLEDB;DATA SOURCE=xx;DATABASE=xx;User ID=sa;Password=xx"
Set RS = Server.CreateObject("ADODB.recordset")
RS.open SQL, dbsecurecon,3,3
If Not RS.EOF Then
TotalRecordCount=Trim(RS("TotalRecordCount"))
Else
TotalRecordCount=0
End If
End Function

Function CategorySingleListInDetail(RowNumber,Category)
SQL=" SELECT * FROM ( "
SQL=SQL & " Select Description, PartNo, "
SQL=SQL & " Row_Number() Over(Order By PartNo) as rownumber, "
SQL=SQL & " Count(*) Over() as TotalRecordCount "
SQL=SQL & " From Products "
SQL=SQL & " where Category = '" & Category & "' ) T1 "
SQL=SQL & " WHERE rownumber = '" & RowNumber & "' "
SQL=SQL & " Order By partno asc "

Set dbsecurecon  = Server.CreateObject("ADODB.Connection")
dbsecurecon = "PROVIDER=SQLOLEDB;DATA SOURCE=X.X.X.X,1533;DATABASE=aviation;User ID=sa;Password=XXXXXXX"
Set RS = Server.CreateObject("ADODB.recordset")
RS.open SQL, dbsecurecon,3,3
If Not RS.EOF Then
PartNo = RS("PartNo")
Description = RS("Description")

p="<table>"
p=p & "<tr><Td colspan=""3"" bgcolor=black><font color=white>"
p=p & "Category: " & Category & "</td></tr>"
p=p & "<tr><td colspan=""3"">Request a Quote:</td></tr>"
p=p & "<tr>"
p=p & "<td>" & PartNo & "</td>"
p=p & "</tr>" 
p=p & "<tr>"
p=p & "<td>" & Description 
p=p & "</td>"
p=p & "<td><br></td>"
p=p & "</tr>"
p=p & "</table>"
TotalRecordCountClient=Trim(TotalRecordCount(Category))
For i = 1  to TotalRecordCountClient
p=p & "<a href=""testplan1.asp?RowNumber=" & i  & "&Category=" & Category & "&PartNo=" & PartNo & """>" & i & "</a>" & " " 
Next
Else
p=""
End If
CategorySingleListInDetail=p
End Function
TotalCount=TotalRecordCount(Category)
RowNumber=request.QueryString("RowNumber")
if RowNumber = "" Then RowNumber = 1 End If
Response.Write CategorySingleListInDetail(RowNumber,Category)
%>
</body>
</html>

Open in new window

0
Comment
Question by:Webboy2008
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 10

Accepted Solution

by:
P1ST0LPETE earned 500 total points
ID: 36514571
This was a fun challenge as I've never used ASP Classic before, and I never write in VB - as I'm a C# guy.
Anyway, here ya go. I tested it out and it works.  Next time you may want to do a better job of hiding your database connection string :-)

HTML Markup:
 
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="WebApplication3.WebForm1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    </div>
    </form>
</body>
</html>

Open in new window



VB Code Behind:
 
Imports System.Data.OleDb

Public Class WebForm1
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim Category As String = "COOLANT"
        Dim TotalCount As Integer = TotalRecordCount(Category)
        Dim RowNumber As Integer = If(String.IsNullOrEmpty(Request.QueryString("RowNumber")), 1, Convert.ToInt32(Request.QueryString("RowNumber")))
        Response.Write(CategorySingleListInDetail(RowNumber, Category))

    End Sub

    Private Function TotalRecordCount(ByVal Category As String) As Integer

        Dim RecordCount As Integer = 0

        Dim SQL As New StringBuilder()
        SQL.Append(" Select Top 1 PartNo, ")
        SQL.Append(" Row_Number() Over(Order By PartNo) rownumber, ")
        SQL.Append(" Count(*) Over() as TotalRecordCount ")
        SQL.Append(" From Products ")
        SQL.Append(" where Category = '" & Category & "' ")
        SQL.Append(" Order By partno asc ")

        Dim connection As New OleDbConnection("PROVIDER=SQLOLEDB;DATA SOURCE=X.X.X.X,1533;DATABASE=aviation;User ID=sa;Password=XXXXXXXX")
        Dim command As New OleDbCommand(SQL.ToString(), connection)
        Dim reader As OleDbDataReader

        Try
            command.Connection.Open()
            reader = command.ExecuteReader()

            While reader.Read()
                RecordCount = Convert.ToInt32(reader("TotalRecordCount"))
            End While

        Catch ex As Exception

        Finally
            command.Connection.Close()
            command.Dispose()
        End Try

        Return RecordCount

    End Function

    Private Function CategorySingleListInDetail(ByVal RowNumber As Integer, ByVal Category As String) As String

        Dim SQL As New StringBuilder()
        SQL.Append(" SELECT * FROM ( ")
        SQL.Append(" Select Description, PartNo, ")
        SQL.Append(" Row_Number() Over(Order By PartNo) as rownumber, ")
        SQL.Append(" Count(*) Over() as TotalRecordCount ")
        SQL.Append(" From Products ")
        SQL.Append(" where Category = '" & Category & "' ) T1 ")
        SQL.Append(" WHERE rownumber = '" & RowNumber & "' ")
        SQL.Append(" Order By partno asc ")

        Dim connection As New OleDbConnection("PROVIDER=SQLOLEDB;DATA SOURCE=X.X.X.X,1533;DATABASE=aviation;User ID=sa;Password=XXXXXXXX")
        Dim command As New OleDbCommand(SQL.ToString(), connection)
        Dim reader As OleDbDataReader

        Dim p As New StringBuilder()

        Try
            command.Connection.Open()
            reader = command.ExecuteReader()

            While reader.Read()

                Dim PartNo As String = reader("PartNo").ToString()
                Dim Description As String = reader("Description").ToString()

                p.Append("<table>")
                p.Append("<tr><Td colspan=""3"" bgcolor=black><font color=white>")
                p.Append("Category: " & Category & "</td></tr>")
                p.Append("<tr><td colspan=""3"">Request a Quote:</td></tr>")
                p.Append("<tr>")
                p.Append("<td>" & PartNo & "</td>")
                p.Append("</tr>")
                p.Append("<tr>")
                p.Append("<td>" & Description)
                p.Append("</td>")
                p.Append("<td><br></td>")
                p.Append("</tr>")
                p.Append("</table>")

                Dim TotalRecordCountClient As Integer = TotalRecordCount(Category)

                For i = 1 To TotalRecordCountClient
                    p.Append("<a href=""testplan1.asp?RowNumber=" & i & "&Category=" & Category & "&PartNo=" & PartNo & """>" & i & "</a>" & " ")
                Next

            End While

        Catch ex As Exception

        Finally
            command.Connection.Close()
            command.Dispose()
        End Try

        Return p.ToString()

    End Function

End Class

Open in new window

0

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question