Groups | Blog | Home
all groups > dotnet ado.net > march 2007 >

dotnet ado.net : Tabledefs and VB.net


Vanny
3/28/2007 4:40:00 PM
I'm really new to vb.net. What I like to know is what would be the code to
read the definition of table or view. Here is the piece of code in VB6 that
try to find a column name called "year" in a view. How to write this in
VB.net?

For Each fldField In gdbOes.TableDefs(viewname)).Fields
strFieldName = fldField.Name
If strFieldName = "year" Then
blnyearFind = True
Exit For
End If
Next

I use odbc connection in vb6 as well as in vb.net. Above, the connection
name is gdbOes.

Thanks in advance for your help

Vanny

RobinS
3/28/2007 8:50:03 PM
It would be helpful to know the data source? Firebird, Oracle, SQLServer,
Access?

Robin S.
------------------------
[quoted text, click to view]

Vanny
3/29/2007 8:45:07 AM
We're using Adaptive Server Anywhere ASA9.

Thanks,
Vanny

[quoted text, click to view]

Paul Clement
3/30/2007 12:27:02 PM
[quoted text, click to view]

¤ We're using Adaptive Server Anywhere ASA9.

If you have an OLEDB provider for this data source then you can probably use GetOleDbSchemaTable.
Below is an example that uses an Access database:

Dim DatabaseConnection As New System.Data.OleDb.OleDbConnection
Dim SchemaTable As DataTable

DatabaseConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Test Files\db1 XP.mdb"

DatabaseConnection.Open()

'Retrieve schema information about Table1 Columns.
SchemaTable =
DatabaseConnection.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Columns, _
New Object() {Nothing, Nothing, "Table1"})

Dim RowCount As Int32
For RowCount = 0 To SchemaTable.Rows.Count - 1
Console.WriteLine(SchemaTable.Rows(RowCount)!COLUMN_NAME.ToString)
Next RowCount

DataGrid1.DataSource = SchemaTable

DatabaseConnection.Close()


Paul
~~~~
Vanny
4/2/2007 12:11:07 PM
Thanks for your help. Unfortunately, this is a group project, I can not use
OLEDB. I could not find the equivalence of this code in odbc:
SchemaTable =
DatabaseConnection.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Columns,
_
New Object() {Nothing, Nothing, "Table1"})
The function Getschema that does work with odbc connection, seems not having
the same purpose. There is another one Getschematable, but it works with
datareader.

Thanks
Vanny

[quoted text, click to view]

Paul Clement
4/3/2007 8:54:10 AM
[quoted text, click to view]

¤ Thanks for your help. Unfortunately, this is a group project, I can not use
¤ OLEDB. I could not find the equivalence of this code in odbc:
¤ SchemaTable =
¤ DatabaseConnection.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Columns,
¤ _
¤ New Object() {Nothing, Nothing, "Table1"})
¤ The function Getschema that does work with odbc connection, seems not having
¤ the same purpose. There is another one Getschematable, but it works with
¤ datareader.
¤

The ODBC provider is rather limited in this respect. I'm not sure what type of database you are
working with but if it's Microsoft Access then ODBC is a poor choice for reasons of stability and
functionality.

If you're working with a server based database then you may be able to tap into the DDL to return
this information.


Paul
~~~~
AddThis Social Bookmark Button