Building Tables on the fly with a data reader

  • Thread starter Thread starter nina297
  • Start date Start date
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
 
Back
Top