I'm trynig to create an application that will connect to any database that i specify and return the colums names within any table that i specify.
I have done the code that establishes the connection but im a bit stumped on how to get the colum names from a tabel and was wondering if anybody had any sourse code for this in VB.
Thanks
Rob
ps: have a good new year !!There are a few ways to accomplish this, depending on why you want the information.
1. Issue a SELECT TOP 0 * FROM <table> query to return the schema without data.
2. Query the syscolumns table. See MSDN for documentation on the sysobjects, syscolumns, and systypes table.
3. Use SQL-DMO objects.|||Yet another approach is to use the FillSchema method for a data adapter. It returns just the column names without any data. The example below is for an Access table and binds the results to a DataGrid for display.
|||FillSchema is exactly what i needed, thanks a million
//C#
string strConn= @."Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User ID=Admin;Data Source=etc.";
OleDbConnection DSConn= new OleDbConnection( strConn );
OleDbDataAdapter da1= new OleDbDataAdapter("SELECT * FROM APIFact", DSConn);
DataTable dt= new DataTable();
da1.FillSchema( dt, SchemaType.Source );
DataGrid1.DataSource = dt;
DataGrid1.DataBind();
Rob
No comments:
Post a Comment