|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Tabledefs and VB.netread 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 It would be helpful to know the data source? Firebird, Oracle, SQLServer,
Access? Robin S. ------------------------ Show quote "Vanny" <li***@bls.gov> wrote in message news:u6tiClXcHHA.648@TK2MSFTNGP04.phx.gbl... > 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 > We're using Adaptive Server Anywhere ASA9.
Thanks, Vanny Show quote "RobinS" <RobinS@NoSpam.yah.none> wrote in message news:V_OdncvhY4fsqpbbnZ2dnUVZ_vKunZ2d@comcast.com... > It would be helpful to know the data source? Firebird, Oracle, SQLServer, > Access? > > Robin S. > ------------------------ > "Vanny" <li***@bls.gov> wrote in message > news:u6tiClXcHHA.648@TK2MSFTNGP04.phx.gbl... >> 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 >> > > On Thu, 29 Mar 2007 08:45:07 -0400, "Vanny" <li***@bls.gov> wrote: ¤ 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 ~~~~ Microsoft MVP (Visual Basic) 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 Show quote "Paul Clement" <UseAdddressAtEndofMess***@swspectrum.com> wrote in message news:7phq03tgeij2060907mvhb5eab39tkpbdh@4ax.com... > On Thu, 29 Mar 2007 08:45:07 -0400, "Vanny" <li***@bls.gov> wrote: > > ¤ 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 > ~~~~ > Microsoft MVP (Visual Basic) On Mon, 2 Apr 2007 12:11:07 -0400, "Vanny" <li***@bls.gov> wrote: ¤ 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 ~~~~ Microsoft MVP (Visual Basic) |
|||||||||||||||||||||||