Building Tables on the fly with a data reader

N

nina297

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("EDCSFAQSConnectionString").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
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top