Solved

asp.net vb.net

Posted on 2011-09-13
4
363 Views
Last Modified: 2012-05-12
convert from classic asp to asp.net / vb.net as follow.
For some reasons, asp.net does not return any values without any error...no idea why?

Function SingleItem(Category,RowNumber)

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=1533;DATABASE=aviation;User ID=sa;Password=1"
Set RS = Server.CreateObject("ADODB.recordset")
RS.open SQL, dbsecurecon,3,3
If Not RS.EOF Then
PartNo = RS("PartNo")
End If
 SingleItem=PartNo
End Function


Private Function SingleItem(ByVal Category As String, ByVal RowNumber As Integer) As String
        Dim strPartNo As String = String.Empty
        Dim myConnection As New SqlConnection
        Dim myCommand As SqlCommand
        Dim dr As SqlDataReader
        Try
            myConnection.ConnectionString = "PROVIDER=SQLOLEDB;DATA SOURCE=1533;DATABASE=aviation;User ID=sa;Password=1"
            myConnection.Open()
            'opening the connection
            'Dim sSQLCmd As String = String.Empty
            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 ")
            myCommand = New SqlCommand(SQL.ToString(), myConnection)
            'executing the command and assigning it to connection
            dr = myCommand.ExecuteReader()

            If Not IsDBNull(dr("PartNo")) Then
                strPartNo = dr("PartNo")

            Else
                strPartNo = "No data"
            End If

            'displaying the data from the table
            dr.Close()

            myConnection.Close()
        Catch e As Exception
        End Try
        Return strPartNo
    End Function
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
  • 2
4 Comments
 
LVL 38

Expert Comment

by:PaulHews
ID: 36529490
You need to call Read on the datareader for one thing...

           dr = myCommand.ExecuteReader()
            If dr.Read() AndAlso Not IsDBNull(dr.GetOrdinal("PartNo")) Then
                strPartNo = dr.GetString(dr.GetOrdinal("PartNo"))
            Else
                strPartNo = "No data"
            End If

Open in new window

0
 
LVL 38

Expert Comment

by:PaulHews
ID: 36529499
Correction:
        If dr.Read() AndAlso Not dr.IsDBNull(dr.GetOrdinal("PartNo")) Then
            strPartNo = dr.GetString(dr.GetOrdinal("PartNo"))
        Else
            strPartNo = "No data"
        End If

Open in new window

0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 36532129
0
 

Author Comment

by:Webboy2008
ID: 36533366
PaulHews:still no data
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

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…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

717 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