473,495 Members | 2,128 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

ASP.NET Datareader

Kosal
68 New Member
Dear Sir/Madam

I would linke you to help me as below:

I want to using datareader and inside datareader I have datareader but I cannot.
I using code as below but error can you help me.

Expand|Select|Wrap|Line Numbers
  1. Dim Category As String = "SELECT catgcode, catgName FROM tblCategories"
  2.         Dim myCommand As New System.Data.SqlClient.SqlCommand(Category, DBTools.gCnn)
  3.         Dim myReader As System.Data.SqlClient.SqlDataReader=Nothing 
  4.         myReader = myCommand.ExecuteReader()
  5.         While myReader.Read()
  6.            Response.Write("<li><span class='folder'>&nbsp;"& myReader("catgName") &"</span>")
  7.             Dim subCategory As String = "SELECT subCatgCode, subCatgName FROM tblSubCategories WHERE catgcode='"& myReader("catgCode") 
  8.             Dim myCommand1 As New System.Data.SqlClient.SqlCommand(subCategory, DBTools.gCnn)
  9.             Dim myReader1 As System.Data.SqlClient.SqlDataReader
  10.             myReader1 = myCommand1.ExecuteReader()
  11.             While myReader1.Read()
  12.             Response.Write("<ul>")
  13.             Response.Write("<li><span class='file'>&nbsp;"& myReader1("subCatgName") &"</span></li>")
  14.             Response.Write("</ul>")
  15.             End While
  16.             myReader1.Close()
  17.             Response.Write("</li>")
  18.         End While
  19.  
  20.        myReader.Close()
  21.        myReader=Nothing 
  22.     DBTools.gCnn.Close()


thanks
Kosal
Jan 1 '10 #1
5 2793
tlhintoq
3,525 Recognized Expert Specialist
TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.
Jan 1 '10 #2
tlhintoq
3,525 Recognized Expert Specialist
I using code as below but error
What is the error? On which line of code?
Jan 1 '10 #3
Frinavale
9,735 Recognized Expert Moderator Expert
Well I think that the error is that the content isn't showing up because they are using Response.Write()

Do not use Response.Write() in your VB.NET or C# code.
Why?
Well, it places the content in an invalid place in the page.
For example, if you use Response.Write() in your VB/C# code it's likely that your output is going to look like:
Expand|Select|Wrap|Line Numbers
  1. <ul>
  2.  <li><span class='folder'> Folder 1 stuff</span></li>
  3.  <li><span class='folder'> Folder 2 stuff</span></li>
  4.  <li><span class='folder'> Folder 3 stuff</span></li>
  5.  <li><span class='folder'> Folder 4 stuff</span></li>
  6. </ul>
  7. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  8. <html xmlns="http://www.w3.org/1999/xhtml"> 
  9.  
  10. ....
Notice how the content is Above the <html> and doctype tags? This is invalid page content.

Instead of using Response.Write consider using the appropriate ASP.NET controls...like the ListView, or the Repeater control something.

-Frinny
Jan 4 '10 #4
Kosal
68 New Member
Dear Sir

As above code error:

While myReader1.Read()
Response.Write("<ul>")
Response.Write("<li><span class='file'>&nbsp;"& myReader1("subCatgName") &"</span></li>")
Response.Write("</ul>")
End While
Jan 5 '10 #5
Frinavale
9,735 Recognized Expert Moderator Expert
Kosal, what is the error message?
If there is no error message then please explain what is wrong?

-Frinny
Jan 5 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

6
363
by: Yasutaka Ito | last post by:
Hi, My friend had a little confusion about the working of DataReader after reading an article from MSDN. Following is a message from him... <!-- Message starts --> I was going thru DataReader...
6
750
by: Ravi | last post by:
Hi, I am not able to understand why a datareader needs a connection to the DB all the time. Here is what I tried. Sqlcommand cmd = ("select * from table1",con) // where con is the connection...
5
5747
by: Jason Huang | last post by:
Hi, Is it possible to bind DataReader to a DataGrid in C# windows form? And how? And can we update data in a DataSet by using the DataReader? Thanks for help. Jason
12
467
by: Thomas Scheiderich | last post by:
I have 2 dropdowns that are exactly the same and I don't want to re-read for each. Is there a way to do something like below where I read the data, bind to depCity1 and then bind to destCity2. ...
20
5508
by: Mark | last post by:
Hi all, quick question , a DataView is memory resident "view" of data in a data table therefore once populated you can close the connection to the database. Garbage collection can then be used to...
2
1561
by: Andrei Pociu | last post by:
In a typical ASP .NET Web Application (website), I'm currently using a class where I declare some public static objects. For example there's the place where I initialize the SqlConnection. Also...
1
3081
by: Brent | last post by:
I'm having a hard time wrapping my head around how to build a multi-dimensional array of n length out of a DataReader loop. Take this pseudo-code: ======================================= public...
7
3373
by: Varangian | last post by:
Hi all, the question I want to ask if the conversion of a DataReader to a Table looping through the DataReader is better than using the Fill Method of the DataAdapter... I'm asking because...
7
2891
by: Diffident | last post by:
Hello All, I would like to use DataReader based accessing in my Data Access Layer (DAL). What is considered to be a best practice while returning from a DAL method that executes a query and...
3
3375
by: Johnny Jörgensen | last post by:
I've got an error that I simply cannot locate: I've got a form in which I use a datareader object to read information from a db. After the read, I close the reader and I dispose of both the...
0
7160
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7196
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6878
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5456
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4897
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4583
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3088
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
649
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.