One record is missing to display in aspx page. But works in SQL qu

G

Guest

One record is missing to display in aspx page. But works in SQL query…

When i run a query in MSSQL I get 3 records. but when i run try to display
it in aspx page it displayes only 2 records..
below is the code.. plz help


Public Class hr
Inherits System.Web.UI.Page
Dim MyCommand As SqlCommand
Dim objUserData As Hashtable
Dim MyDataReader As SqlDataReader
Dim MyConnection As SqlConnection

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
MyConnection = New SqlConnection("Persist Security
Info=False;Server=bglamdweb;Database=AMDIndia;User ID=saassword=IEC123")
Dim strSelect As String = "SELECT TOP 6* FROM Amdindia.dbo.Tbl_News WHERE
(News_Dprt_ID=1) ORDER BY News_ID DESC"
MyCommand = New SqlCommand(strSelect, MyConnection)
MyCommand.CommandType = CommandType.Text
MyConnection.Open()
MyDataReader = MyCommand.ExecuteReader()
Dim myGridText As String
If MyDataReader.HasRows Then MyDataReader.Read()
myGridText = "<table width='100%' border='0'>"
Do While MyDataReader.Read


myGridText = myGridText + "<tr><td class='date'>" &
FormatDateTime(MyDataReader("News_Date"), vbShortDate) & "</td></tr>"
myGridText = myGridText + "<tr><td class='news_title'>" &
MyDataReader("News_Title") & "</td></tr>"
myGridText = myGridText + "<tr><td class='news_content'>" &
MyDataReader("News_Detail") & "</td></tr>"
Loop
myGridText = myGridText + "</table>"
myGrid.Text = myGridText
MyDataReader.Close()
MyConnection.Close()
End Sub
End Class

myGrid is a label....
 
B

Brian Begy

OK. First off, the label is probably not the best way to render tables.
Adding an asp.net table is more what you want since labels tend to
render as span objects with unintended consequences.

Second, you want to make sure that you really have a data problem. Have
you tried putting a breakpoint on to confirm that the row count is
different?

-Brian


BugSentry needs beta testers!
www.bugsentry.com
 
G

Guest

yes i changed it into label..

then i came to

If MyDataReader.HasRows Then MyDataReader.Read()
myGridText = "<table width='100%' border='0'>"
Do While MyDataReader.Read

The using the "MyDataReader.Read()" takes the first record..just commented
it and it workd..

thx
any
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top