Solved

asp to asp.net / vb.net

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

778 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