Solved

asp.net vb.net

Posted on 2011-09-13
4
357 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
  • 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

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…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

758 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

18 Experts available now in Live!

Get 1:1 Help Now