Sandhurst
Sandhurst

Reputation:

How To Change Schema of DataSet at Runtime C# ASP.Net

I would like to know how to change the schema of DataSet at Runtime

Upvotes: 1

Views: 2740

Answers (2)

Harish
Harish

Reputation:

We had a similar problem. Here is what we did. The database server stored times in GMT. And, the web service returned all GMT times. So, in C# we set the timezones to UTC and displayed using localization.

        DataSet newDset = srcTable.Clone();
        DataTable dTable = newDset.Tables[0];

        for (int j = 0; j < dTable.Columns.Count; j++)
        {
            if (dTable.Columns[j].DataType.ToString() == "System.DateTime")
            {
                dTable.Columns[j].DateTimeMode = DataSetDateTime.Utc;
            }
        }

Upvotes: 0

Marc Gravell
Marc Gravell

Reputation: 1062855

Is it a typed or untyped DataSet? For typed, this probably isn't a good idea to start with. But for untyped, just manipulate the Columns etc on tables, or add/remove tables/associations. Was there something specific that was being painful? Or do you mean the schema for the adapter?

Personally, I very rarely use DataSet, preferring standard POCO classes for the entities (perhaps with ORM like LINQ-to-SQL/Entity Framework/NHibernate). But some people like them...

Upvotes: 1

Related Questions