.NETGURU
Loading schema
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngdata' list.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.

dave wanta (VIP)
Hi All,
How do I get a datable schema without loading all the data from the database? I need to do this for both OleDb and Sql. Specifically, I just need the column names of the resulting datatable.

I have a function that gets passed some sql or a stored procedure and returns a datatable. I'd like to provide the caller the capability to only return an empty datatable ( really, just the table column names only).

Is this possible?

Thanks a bunch!

--dave
Reply to this message...
 
    
Dan Wahlin
The easiest way is to do the following (I'm guessing there may be some
other tricks as well):

SELECT * FROM Customers WHERE 1=0

You can see an example of using this to load the schema into a DataSet
at the following URL:

http://www.xmlforasp.net/codebank/util/srcview.aspx?path=../../codebank/" target="_blank">http://www.xmlforasp.net/codebank/util/srcview.aspx?path=../../codebank/
System.Data/YahooStores/YahooStores.src
<http://www.xmlforasp.net/codebank/util/srcview.aspx?path=../../codebank
/System.Data/YahooStores/YahooStores.src&file=XmlImporter.cs&font=3>
&file=XmlImporter.cs&font=3

(watch for wrapping)

HTH,

Dan

Wahlin Consulting LLC

Microsoft MVP - ASP.NET

http://www.XMLforASP.Net <http://www.xmlforasp.net/> : #1 ASP.NET XML
Resource

XML
<http://www.amazon.com/exec/obidos/ASIN/0672320398/ref=ase_xmlforaspnetd
-20/104-7101530-2681531> for ASP.NET Developers by Dan Wahlin in
bookstores everywhere!

-----Original Message-----
From: dave wanta [mailto:Click here to reveal e-mail address]
Sent: Sunday, May 26, 2002 2:02 PM
To: aspngdata
Subject: [aspngdata] Loading schema

Hi All,

How do I get a datable schema without loading all the data from the
database? I need to do this for both OleDb and Sql. Specifically, I
just need the column names of the resulting datatable.

I have a function that gets passed some sql or a stored procedure and
returns a datatable. I'd like to provide the caller the capability to
only return an empty datatable ( really, just the table column names
only).

Is this possible?

Thanks a bunch!

--dave

| [aspngdata] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngdata.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives
Reply to this message...
 
    
Steve Sharrock (VIP)
You can also use the DataAdapter's FillSchema method to load a DataSet
with the table's schema. I don't know if this is more efficient than
Dan's method or not--I use both from time to time when I'm doing an
insert and don't do a select first.

DataSet ds = new DataSet();

da.FillSchema(ds, SchemaType.Source, "Listing");

Steve Sharrock
programmer / designer
www.sharkcode.com <http://www.sharkcode.com/>

-----Original Message-----
From: Dan Wahlin [mailto:Click here to reveal e-mail address]
Sent: Sunday, May 26, 2002 3:30 PM
To: aspngdata
Subject: [aspngdata] RE: Loading schema

The easiest way is to do the following (I'm guessing there may be some
other tricks as well):

SELECT * FROM Customers WHERE 1=0

You can see an example of using this to load the schema into a DataSet
at the following URL:

http://www.xmlforasp.net/codebank/util/srcview.aspx?path=../../codebank" target="_blank">http://www.xmlforasp.net/codebank/util/srcview.aspx?path=../../codebank/" target="_blank">http://www.xmlforasp.net/codebank/util/srcview.aspx?path=../../codebank" target="_blank">http://www.xmlforasp.net/codebank/util/srcview.aspx?path=../../codebank/
System.Data/YahooStores/YahooStores.src
<http://www.xmlforasp.net/codebank/util/srcview.aspx?path=../../codebank" target="_blank">http://www.xmlforasp.net/codebank/util/srcview.aspx?path=../../codebank
/System.Data/YahooStores/YahooStores.src&file=XmlImporter.cs&font=3>
&file=XmlImporter.cs&font=3

(watch for wrapping)

HTH,

Dan

Wahlin Consulting LLC

Microsoft MVP - ASP.NET

http://www.XMLforASP.Net <http://www.xmlforasp.net/> : #1 ASP.NET XML
Resource

XML
<http://www.amazon.com/exec/obidos/ASIN/0672320398/ref=ase_xmlforaspnetd
-20/104-7101530-2681531> for ASP.NET Developers by Dan Wahlin in
bookstores everywhere!

-----Original Message-----
From: dave wanta [mailto:Click here to reveal e-mail address]
Sent: Sunday, May 26, 2002 2:02 PM
To: aspngdata
Subject: [aspngdata] Loading schema

Hi All,

How do I get a datable schema without loading all the data from the
database? I need to do this for both OleDb and Sql. Specifically, I
just need the column names of the resulting datatable.

I have a function that gets passed some sql or a stored procedure and
returns a datatable. I'd like to provide the caller the capability to
only return an empty datatable ( really, just the table column names
only).

Is this possible?

Thanks a bunch!

--dave

| [aspngdata] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngdata.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives

| [aspngdata] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngdata.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives
Reply to this message...
 
    
Dan Wahlin
Actually..I like the FillSchema() method you mention better. I'd seen
that awhile back but never actually tried it out. Looks much cleaner.
:-)

Dan

Wahlin Consulting LLC

Microsoft MVP - ASP.NET

http://www.XMLforASP.Net <http://www.xmlforasp.net/> : #1 ASP.NET XML
Resource

XML
<http://www.amazon.com/exec/obidos/ASIN/0672320398/ref=ase_xmlforaspnetd
-20/104-7101530-2681531> for ASP.NET Developers by Dan Wahlin in
bookstores everywhere!

-----Original Message-----
From: Steve Sharrock [mailto:Click here to reveal e-mail address]
Sent: Sunday, May 26, 2002 4:49 PM
To: aspngdata
Subject: [aspngdata] RE: Loading schema

You can also use the DataAdapter's FillSchema method to load a DataSet
with the table's schema. I don't know if this is more efficient than
Dan's method or not--I use both from time to time when I'm doing an
insert and don't do a select first.

DataSet ds = new DataSet();

da.FillSchema(ds, SchemaType.Source, "Listing");

Steve Sharrock

programmer / designer

www.sharkcode.com <http://www.sharkcode.com/>

-----Original Message-----
From: Dan Wahlin [mailto:Click here to reveal e-mail address]
Sent: Sunday, May 26, 2002 3:30 PM
To: aspngdata
Subject: [aspngdata] RE: Loading schema

The easiest way is to do the following (I'm guessing there may be some
other tricks as well):

SELECT * FROM Customers WHERE 1=0

You can see an example of using this to load the schema into a DataSet
at the following URL:

http://www.xmlforasp.net/codebank/util/srcview.aspx?path=../../codebank" target="_blank">http://www.xmlforasp.net/codebank/util/srcview.aspx?path=../../codebank/" target="_blank">http://www.xmlforasp.net/codebank/util/srcview.aspx?path=../../codebank" target="_blank">http://www.xmlforasp.net/codebank/util/srcview.aspx?path=../../codebank/
System.Data/YahooStores/YahooStores.src
<http://www.xmlforasp.net/codebank/util/srcview.aspx?path=../../codebank" target="_blank">http://www.xmlforasp.net/codebank/util/srcview.aspx?path=../../codebank
/System.Data/YahooStores/YahooStores.src&file=XmlImporter.cs&font=3>
&file=XmlImporter.cs&font=3

(watch for wrapping)

HTH,

Dan

Wahlin Consulting LLC

Microsoft MVP - ASP.NET

http://www.XMLforASP.Net <http://www.xmlforasp.net/> : #1 ASP.NET XML
Resource

XML
<http://www.amazon.com/exec/obidos/ASIN/0672320398/ref=ase_xmlforaspnetd
-20/104-7101530-2681531> for ASP.NET Developers by Dan Wahlin in
bookstores everywhere!

-----Original Message-----
From: dave wanta [mailto:Click here to reveal e-mail address]
Sent: Sunday, May 26, 2002 2:02 PM
To: aspngdata
Subject: [aspngdata] Loading schema

Hi All,

How do I get a datable schema without loading all the data from the
database? I need to do this for both OleDb and Sql. Specifically, I
just need the column names of the resulting datatable.

I have a function that gets passed some sql or a stored procedure and
returns a datatable. I'd like to provide the caller the capability to
only return an empty datatable ( really, just the table column names
only).

Is this possible?

Thanks a bunch!

--dave

| [aspngdata] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngdata.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives

| [aspngdata] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngdata.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives

| [aspngdata] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngdata.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives
Reply to this message...
 
 
System.Data.Common.DataAdapter
System.Data.DataSet
System.Data.SchemaType




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification