Solved

asp to asp.net / vb.net

Posted on 2011-09-09
1
374 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

920 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

17 Experts available now in Live!

Get 1:1 Help Now