"Randy" <ra************ @gmail.comwrote in message
news:11******** **************@ r30g2000prh.goo glegroups.com.. .
Yes.
Try this:
Here are all of the properties (and their types) you can retrieve for the
data columns using a DataReader.
col name = ColumnName, type = System.String
col name = ColumnOrdinal, type = System.Int32
col name = ColumnSize, type = System.Int32
col name = NumericPrecisio n, type = System.Int16
col name = NumericScale, type = System.Int16
col name = IsUnique, type = System.Boolean
col name = IsKey, type = System.Boolean
col name = BaseServerName, type = System.String
col name = BaseCatalogName , type = System.String
col name = BaseColumnName, type = System.String
col name = BaseSchemaName, type = System.String
col name = BaseTableName, type = System.String
col name = DataType, type = System.Type
col name = AllowDBNull, type = System.Boolean
col name = ProviderType, type = System.Int32
col name = IsAliased, type = System.Boolean
col name = IsExpression, type = System.Boolean
col name = IsIdentity, type = System.Boolean
col name = IsAutoIncrement , type = System.Boolean
col name = IsRowVersion, type = System.Boolean
col name = IsHidden, type = System.Boolean
col name = IsLong, type = System.Boolean
col name = IsReadOnly, type = System.Boolean
col name = ProviderSpecifi cDataType, type = System.Type
col name = DataTypeName, type = System.String
col name = XmlSchemaCollec tionDatabase, type = System.String
col name = XmlSchemaCollec tionOwningSchem a, type = System.String
col name = XmlSchemaCollec tionName, type = System.String
col name = UdtAssemblyQual ifiedName, type = System.String
col name = NonVersionedPro viderType, type = System.Int32
Here's how I got this list; tableName is passed in as a String. This shows
the columns you can get, and then shows selected values for each column
defined in the table.
Dim cn As New SqlConnection(M y.Settings.DBCo nnString)
'put the table name in brackets in case it has spaces in it
Dim SQLString As String = "SELECT * FROM [" & tableName & "]"
Try
cn.Open()
Dim cmd As New SqlCommand(SQLS tring, cn)
Dim rdr As SqlDataReader =
cmd.ExecuteRead er(CommandBehav ior.KeyInfo)
Dim tbl As DataTable = rdr.GetSchemaTa ble
'This shows all of the information you can access about each
column.
For Each col As DataColumn In tbl.Columns
Debug.Print("co l name = " & col.ColumnName & _
", type = " & col.DataType.To String)
Next
For Each row As DataRow In tbl.Rows
'DataTypeName actually gives the same
' data type name as is displayed in SQLServer
Debug.Print("{0 }, ColumnSize = {1}, DataType = {2},
DataTypeName = {3}, IsExpression = {4} ", _
row("ColumnName "), row("ColumnSize "), row("DataType") , _
row("DataTypeNa me"), row("IsExpressi on"))
Next
rdr.Close()
Catch
MessageBox.Show ("Error opening the connection to the database.")
Finally
cn.Close()
End Try
I also know how to get a list of tables if you're interested.
Robin S.
Ts'i mahnu uterna ot twan ot geifur hingts uto.