asp.net vb.net

Posted on 2011-09-13
Medium Priority
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=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
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
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
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 2000 total points
ID: 36532129

Author Comment

ID: 36533366
PaulHews:still no data

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

801 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