473,397 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Building Tables on the fly with a data reader

Hello,

I'm a newbie to .NET. Could someone please assist me. I am pulling
topics, questions and answers from a database. I've set all of this
code in the code behind page which works. I have the info going into
text boxes but would prefer it to all be displayed in a table. How do
I set that up, what's the code for that?

Dim cmd As New Data.SqlClient.SqlCommand
Dim con As New Data.SqlClient.SqlConnection
Dim rd As Data.SqlClient.SqlDataReader = Nothing
Dim sb As New StringBuilder

Try

con.ConnectionString =
ConfigurationManager.ConnectionStrings("EDCSFAQSCo nnectionString").ConnectionString
con.Open()
sb.Append("GetTopicsNQues")
cmd.Connection = con
cmd.CommandType = Data.CommandType.Text
cmd.CommandText = sb.ToString

rd = cmd.ExecuteReader
sb.Remove(0, sb.Length)
If Not (rd Is Nothing) Then
While (rd.Read)
Topic.Text = rd.Item("Topics")
Questions.Text = rd.Item("Questions")
Answers.Text = rd.Item("Answer")
End While
End If

Catch ex As Exception
'Display the full description of the error
Response.Write(ex.StackTrace.ToString & "<br>" &
ex.Message.ToString & "<br>")
Finally
If Not (rd Is Nothing) Then
If Not rd.IsClosed Then rd.Close()
End If
If Not (rd Is Nothing) Then
If Not rd.IsClosed Then rd.Close()
End If
If Not (cmd Is Nothing) Then cmd.Dispose()
If Not (con Is Nothing) Then
If con.State = Data.ConnectionState.Open Then
con.Close()
con.Dispose()
End If
End Try

Thanks so much for your help.

Nina

Jun 26 '07 #1
1 1167


Binding your IDataReader to a asp:repeater is my suggestion.

IF you need Nesting, then following the google trail:

http://www.google.com/search?hl=en&q=nested+repeater



"nina297" <ni************@ssa.govwrote in message
news:11**********************@o61g2000hsh.googlegr oups.com...
Hello,

I'm a newbie to .NET. Could someone please assist me. I am pulling
topics, questions and answers from a database. I've set all of this
code in the code behind page which works. I have the info going into
text boxes but would prefer it to all be displayed in a table. How do
I set that up, what's the code for that?

Dim cmd As New Data.SqlClient.SqlCommand
Dim con As New Data.SqlClient.SqlConnection
Dim rd As Data.SqlClient.SqlDataReader = Nothing
Dim sb As New StringBuilder

Try

con.ConnectionString =
ConfigurationManager.ConnectionStrings("EDCSFAQSCo nnectionString").Connectio
nString
con.Open()
sb.Append("GetTopicsNQues")
cmd.Connection = con
cmd.CommandType = Data.CommandType.Text
cmd.CommandText = sb.ToString

rd = cmd.ExecuteReader
sb.Remove(0, sb.Length)
If Not (rd Is Nothing) Then
While (rd.Read)
Topic.Text = rd.Item("Topics")
Questions.Text = rd.Item("Questions")
Answers.Text = rd.Item("Answer")
End While
End If

Catch ex As Exception
'Display the full description of the error
Response.Write(ex.StackTrace.ToString & "<br>" &
ex.Message.ToString & "<br>")
Finally
If Not (rd Is Nothing) Then
If Not rd.IsClosed Then rd.Close()
End If
If Not (rd Is Nothing) Then
If Not rd.IsClosed Then rd.Close()
End If
If Not (cmd Is Nothing) Then cmd.Dispose()
If Not (con Is Nothing) Then
If con.State = Data.ConnectionState.Open Then
con.Close()
con.Dispose()
End If
End Try

Thanks so much for your help.

Nina

Jun 26 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Marc R. Bertrand | last post by:
Hello, Do some of you know some pretty good books or web tutorials on building databases, if any? By that I mean, when looking at a business, the sound way of choosing the proper fields and the...
13
by: royaltiger | last post by:
I am trying to copy the inventory database in Building Access Applications by John L Viescas but when i try to run the database i get an error in the orders form when i click on the allocate...
6
by: ARC | last post by:
I'm almost ready to build an upgrade routine for a commercial app that will need to import data from an existing Access 97 back-end database to an Access 2007 back-end blank database. Ideally, it...
1
by: dotnetnovice | last post by:
Hi dear fellows...i am a newbie in C# and practicing it hardly to learn it. Actually i am reading a table from data base through data reader and displaying it in the gridview and i am doing well...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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
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...
0
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
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,...

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.