•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 455,962 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,578 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 1069 | Replies: 1 | Solved
![]() |
•
•
Join Date: Sep 2007
Posts: 1,058
Reputation:
Rep Power: 4
Solved Threads: 61
I am having a problem with my datalist and repeaters. Below is the code. For some reason, when it searches the database and returns results, it counts the correct number of results, but only displays the correct number minus one. So if it returns 3 results, it only displays 2, returns 9, displays 8. This is true for the first two repeaters bound on the first SQL query. The second query counts the right number of records, but doesn't bind to the control like it is supposed to! I get no errors, just no records! Thank you.
Oh and if you have the expertise to combine these two queries into one, that would be greatly appreciated as I am not as fluent with queries as I am with other programming. Keep in mind, they have different limits (query 1 has limit of 5, query 2 has limit of 12).
And any opinions on how to make the code better or more efficient, feel free to criticize. Thank you.
if Not Page.IsPostBack then
if Not Session("UAID") Is Nothing then
Dim conPubs As New OdbcConnection( System.Configuration.ConfigurationManager.AppSettings.Get("ConnectionString") )
Dim dtrReader As OdbcDataReader
Dim strUAID As String = Session("UAID")
Dim intOnlineFriends As Integer = 0
Dim cmdSelect As New OdbcCommand( "SELECT b.*, c.*, a.Views, a.MainPic, a.UserName, (SELECT COUNT(CommentID) FROM ProfileComments WHERE ReceiveUserID=? and WasRead=0) As intComments, (SELECT COUNT(MessageID) FROM Messages WHERE ReceiveUserID=? and WasRead=0) As intMessages FROM Users a LEFT JOIN ProfileComments b ON b.ReceiveUserID=a.UserID LEFT JOIN Messages c ON c.ReceiveUserID=a.UserID WHERE a.UserID=? LIMIT 5", conPubs )
cmdSelect.Parameters.AddWithValue( "?ReceiveUserID", strUAID )
cmdSelect.Parameters.AddWithValue( "?ReceiveUserID", strUAID )
cmdSelect.Parameters.AddWithValue( "?UserID", strUAID )
Dim cmdSelect2 As New OdbcCommand( "SELECT (SELECT COUNT(UserID) As intOnlineFriends FROM Users WHERE Logged=1 AND UserID IN (SELECT FriendID FROM ProfileFriends WHERE UserID=?)) As intOnlineFriends, MainPic, UserID FROM Users WHERE Logged=1 AND UserID IN (SELECT FriendID FROM ProfileFriends WHERE UserID=?) LIMIT 12", conPubs )
cmdSelect2.Parameters.AddWithValue( "?UserID", strUAID )
cmdSelect2.Parameters.AddWithValue( "?UserID", strUAID )
conPubs.Open()
dtrReader = cmdSelect.ExecuteReader()
if dtrReader.HasRows then
while dtrReader.Read()
ltlUserName.Text = dtrReader("UserName")
ltlMainPic.Text = "<img src=""/Profiles/" & Session("UAID") & "/" & dtrReader("MainPic") & """ alt="""""" />"
if dtrReader("intComments") > 0 then ltlComments.Text = dtrReader("intComments") & " New Comments!"
if dtrReader("intMessages") > 0 then ltlMessages.Text = dtrReader("intMessages") & " New Messages!"
ltlViews.Text = FormatNumber(dtrReader("Views"),0)
rpComments.DataSource = dtrReader
rpComments.DataBind()
rpMessages.DataSource = dtrReader
rpMessages.DataBind()
end while
dtrReader.Close()
dtrReader = cmdSelect2.ExecuteReader()
if dtrReader.HasRows then
while dtrReader.Read()
ltlOnlineFriends.Text = dtrReader("intOnlineFriends") & " Friends are Online Now!"
end while
dlOnlineFriends.DataSource = dtrReader
dlOnlineFriends.DataBind()
end if
end if
dtrReader.Close()
conPubs.Close()
if conPubs.State = ConnectionState.Open then conPubs.Close()
else
response.Redirect("/home.aspx")
end if
end ifAnd any opinions on how to make the code better or more efficient, feel free to criticize. Thank you.
•
•
Join Date: Sep 2007
Posts: 1,058
Reputation:
Rep Power: 4
Solved Threads: 61
Nevermind, after walking away and thinking about it, I realized that I made a big mistake. I read all the data, then bound it. The reason why one row was always missing is that during the while read segment, I bound the data eternally. And the reason why the other repeater wasn't showing anything is that I bound the data after reading through the entire datareader. So it bound the left overs, which was nothing.
![]() |
•
•
•
•
•
•
•
•
DaniWeb ASP.NET Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Cross page posting confusion (ASP.NET)
- Literal vs Repeater/Datalist for 2 values (ASP.NET)
- Datalist Repeater Help (ASP.NET)
- Configuration Error (ASP.NET)
- dynamic tables (ASP.NET)
- Nest Datagrids (ASP.NET)
Other Threads in the ASP.NET Forum
- Previous Thread: Social Software Developer Opening at Telligent Systems
- Next Thread: Search records in a database



Linear Mode