Ejecutar una sentencia Select
Artículo por Club Developers · 11 mayo 2006
2041 vistas
Usaremos los objetos Command y DataReader.
Vemos un ejemplo con SQL Server
Vemos un ejemplo con SQL Server
vbnet
Trace.Listeners.Add(New TextWriterTraceListener(Console.Out)) Dim connectString As String = "database=test;server=SRV01;User ID=samfisher;pwd=echelon" Dim connection As SqlConnection = New SqlConnection(connectString) connection.Open() Dim command As SqlCommand = New SqlCommand("SELECT * FROM usr_contract", connection) Dim reader As SqlDataReader = command.ExecuteReader Dim row As Object() = Nothing While reader.Read If row Is Nothing Then row = New Object(reader.FieldCount) {} End If reader.GetValues(row) Dim i As Integer = 0 While i < row.GetLength(0) If Not row(i) Is Nothing AndAlso Not (row(i) Is DBNull.Value) Then Trace.Write(row(i).ToString()) Else Trace.Write("NULL") End If If i < row.GetUpperBound(0) Then Trace.Write(" | ") End If i = i + 1 End While Trace.Write(vbCrLf) End While