Solved

asp to asp.net / vb.net

Posted on 2011-09-09
1
373 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
1 Comment
 
LVL 10

Accepted Solution

by:
P1ST0LPETE earned 500 total points
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
This video discusses moving either the default database or any database to a new volume.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

772 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now