Imports System
Imports System.Data
Imports System.Data.SqlClient
public class MainClass
Shared Sub Main()
Dim thisConnection As New SqlConnection("server=(local)\SQLEXPRESS;" & _
"integrated security=sspi;database=MyDatabase")
Dim sql As String = "SELECT * FROM Employee"
Dim thisCommand As New SqlCommand(sql, thisConnection)
Try
thisConnection.Open()
Console.WriteLine("Connection Opened")
Dim thisReader As SqlDataReader = thisCommand.ExecuteReader()
Dim schema As DataTable = thisReader.GetSchemaTable()
For Each row As DataRow In schema.Rows
For Each col As DataColumn In schema.Columns
Console.WriteLine(col.ColumnName & " = " & row(col).ToString())
Next
Console.WriteLine("---------------")
Next
thisReader.Close()
Catch ex As SqlException
Console.WriteLine("Error: " & ex.ToString())
Finally
thisConnection.Close()
Console.WriteLine("Connection Closed")
End Try
End Sub
End Class
|