Blog Schröder

Sammlung von Codeschnipseln zu Programmierproblemen.
Daten aus fremden Quellen unterliegen deren Rechten.
Siehe auch: Disclaimer auf www.computer-schroeder.de

Donnerstag, 16. August 2007

SqlDataReader

Dim con As SqlConnection = GetConnection()
Dim sql As String
sql = "SELECT AnredeID, Anrede FROM dbo.Anreden"
Dim cdo As New SqlCommand(sql, con)

Dim sdr As SqlDataReader = cdo.ExecuteReader()
Do While sdr.Read
txtResult.Text = txtResult.Text & sdr.GetInt32(0).ToString & " " & sdr.GetString(1) & vbNewLine
Loop
sdr.Close()

Private Function GetConnection() As SqlConnection
Dim conString As String
conString = "Server=BEVPC
SQLExpress;database=MSDNSolve;Integrated Security=true"
Dim con As SqlConnection = Nothing
Try
con = New SqlConnection(conString)
con.Open()
Catch ex As Exception
Throw (ex)
End Try
Return con
End Function

Links zu diesem Post:

Link erstellen

<< Startseite