18/08/2009 Development / asp.net

Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Data
Imports System.Data.SqlClient
Imports System.Globalization

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Dim strConexao As String = "Data Source=.\SQLEXPRESS;....."
Dim sSql As String = "SELECT Count(Nome) AS Total FROM Clientes; SELECT Nome, Email FROM Clientes"
Dim conn As SqlConnection = New SqlConnection(strConexao)

Dim r As SqlDataReader
Dim cmd As SqlCommand = New SqlCommand(sSql, conn)
cmd.CommandType = CommandType.Text

conn.Open()

r = cmd.ExecuteReader(CommandBehavior.CloseConnection)
r.Read()

Dim t As Integer = r.GetOrdinal("Total")
Response.Write(
"Total de Registros: " & r.GetInt32(t))

'****************** AQUI PASSA PRO PROXIMO SELECT

r.NextResult()

If (r.HasRows) Then
Dim nome As String = r.GetOrdinal("Nome")
Dim email As String = r.GetOrdinal("Email")

Response.Write("<table><tr><td><b>Nome</b></td><td><b>E-mail</b></td></tr>")

Dim ci As CultureInfo = New CultureInfo("pt-BR")
While (r.Read())
Response.Write(
"<tr><td>" + r.GetString(nome) + "</td><td>" + r.GetString(email) + "</td></tr>")
End While

Response.Write("</table>")
End If

If Not (r.IsClosed) Then
r.Close()
End If

End Sub

'****************** FIM