Solved

asp to asp.net / vb.net

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

695 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