views:

25

answers:

1

Hi!

I'm populating a Repeater Control dynamically based on a querystring value. On Page_Load, the page executes a function that gets info from the database and loads it into a DataSet is then used to populate the repeater.

The issue is that directly after truncating the table, it still appears to be returning a row...

Here's my code:

Private g As New Globals

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim CommentData As DataSet = g.GetComments(Request.QueryString("i"))
    ' Had the page tell me how many rows were in the table
    MsgBox(CommentData.Tables(0).Rows.Count.ToString)
    If CommentData.Tables(0).Rows.Count = 0 Then
        rptComments.Visible = False
    Else
        rptComments.DataSource = CommentData
        rptComments.DataBind()
    End If

' Heres g.GetComments()
Public Function GetComments(ByVal ArticleID As Integer) As DataSet
    Dim sql As String = "SELECT [CommentID], [Username] ,[Email] ,[URL] ,[CommentText] FROM Comments " & _
                        "WHERE ArticleID = " & ArticleID & " AND ApprovedYN = 'Yes' AND DeletedYN = 'No'"

    MyAdapter.SelectCommand = New SqlCommand(sql, conn)
    MyAdapter.Fill(MyData)

    Return MyData
End Function

The idea is that the Function will get all rows in the Comments table associated with the ArticleID passed to it from the QueryString, but I can't understand why it's returning a row when there aren't any in the table.

EDIT

I have another DataSet being created earlier and when I add the following, I get data from the 1st DataSet:

MsgBox(CommentData.Tables(0).Rows(0)(0).ToString)

I get the article's title which, as you can see from my code above, is not supposed to be in this DataSet...

Any ideas?

Thanks in advance!

A: 

Problem solved!!!

Having created 2 DataSets in the same Sub seems to confuse something on the site... All I did to fix the problem was to clear the first DataSet after having used it to populate my page's content areas, see the following:

If DataSet1 IsNot Nothing Then
    DataSet1.Clear()
End If

Dim DataSet2 As DataSet = g.GetComments(Request.QueryString("i"))
....
Logan Young