How to get meta data information of table

Goldytech
Posted by Goldytech under Others category on | Views : 3079
Suppose you are required to get the table structure information like what are its columns names and what are their data types whether it accepts null values etc
Here is it how you can extract that info programatically with ADO.net

Sub GetTableMetaData()
Dim con As New SqlConnection("your db connection string")
con.Open()
Dim cmd As New SqlCommand("Select * from yourTblName")
cmd.Connection = con
Dim rdr As SqlDataReader
rdr = cmd.ExecuteReader
Dim tbl As DataTable
tbl = rdr.GetSchemaTable
For Each row As DataRow In tbl.Rows
Console.WriteLine("{0}: {1} :{2}", row("ColumnName"), row("DataType"), row("AllowDBnull"))
Next
End Sub

Comments or Responses

Login to post response