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

Function SingleItem(Category,RowNumber)

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") SQL, dbsecurecon,3,3
If Not RS.EOF Then
PartNo = RS("PartNo")
End If
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
            myConnection.ConnectionString = "PROVIDER=SQLOLEDB;DATA SOURCE=1533;DATABASE=aviation;User ID=sa;Password=1"
            '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")

                strPartNo = "No data"
            End If

            'displaying the data from the table

        Catch e As Exception
        End Try
        Return strPartNo
    End Function
Question by:Webboy2008
  • 2
LVL 38

Expert Comment

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"))
                strPartNo = "No data"
            End If

Open in new window

LVL 38

Expert Comment

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

Open in new window

LVL 83

Accepted Solution

CodeCruiser earned 500 total points
ID: 36532129

Author Comment

ID: 36533366
PaulHews:still no data

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

Suggested Solutions

Title # Comments Views Activity
VB.Net How to Exit Sub - Exit Form??? 5 51
Replace &lt; with < 14 56
Server Error 11 47
VB.Net - Windows UserName index and length error 4 22
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my 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…
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 …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

867 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

22 Experts available now in Live!

Get 1:1 Help Now