Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / ADO.NET / May 2005

Tip: Looking for answers? Try searching our database.

DA.Fill Schema Retrieval

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Christopher Weaver - 20 May 2005 22:56 GMT
It appears that the DA's Fill method does not grab the schema in situations
like this:

TasksCommandText = "SELECT * FROM \"tblTasks\" " + sTasksWhere +
sTasksOrderBy;
cmd.CommandText = TasksCommandText;
odbcDA_TaskActivities.SelectCommand = cmd;
dsTaskActivities.Clear();
odbcDA_TaskActivities.Fill(dsTaskActivities, "Tasks");

The DataSet Table "Tasks" doesn't get any of the constraints or PK
information from tblTasks. So what's the best way to go about getting the
schema and applying it to the DataTable?  I've looked at FillSchema but it
creates tables of predefined names (Table1, Table2, etc.) with equally
useless column names.  My code is written to reflect more meaningful names,
their actual names.  Is there a way to get the schema and use the actual
identifiers, both column names and table names?  What's the conventional way
of doing this?
Piyush Thakuria - 25 May 2005 04:50 GMT
Hi,

There are more then one ways to fetch the schema of the table. But in your
case it seems that you want to get the Primary key, column Names, Table Names
also. So the code given below best suits your requirements.

The code is written in C#.

SqlConnection sqlConnect = new SqlConnection();    
            sqlConnect.ConnectionString =
System.Configuration.ConfigurationSettings.AppSettings.Get("CONN_STR");
            sqlConnect.Open();
            DataSet dtEmployee = new DataSet();
            SqlCommand cmdEmployee = new SqlCommand("select * from
Employees",sqlConnect);
            SqlDataAdapter dtaNorthwind = new SqlDataAdapter(cmdEmployee);
dtaNorthwind.FillSchema(dtEmployee,System.Data.SchemaType.Mapped,"Employee");

You can see in the immediate window the following results:

?dtEmployee.Tables[0].PrimaryKey[0].ColumnName  
"EmployeeID"
?dtEmployee.Tables[0].TableName  
"Employee"
?dtEmployee.Tables[0].Columns[0].ColumnName
"EmployeeID"

The fillSchema Method is used in the above e.g. with SchemaType.Mapped.

There are other ways also to fetch the schema, but the above method is the
best fit for your requirements.

Thanks and Regards,
Signature

Piyush Thakuria
Technical Lead

> It appears that the DA's Fill method does not grab the schema in situations
> like this:
[quoted text clipped - 14 lines]
> identifiers, both column names and table names?  What's the conventional way
> of doing this?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.