views:

1035

answers:

2

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

+1  A: 

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...

Marc Gravell
The Problem was that my DataSet was populated using a WebService, The DateTime values were getting modified in the dataset as the TimeZones are different. So I was just trying to convert the DateTime column to Date or string type
Ah... you're trying to change the data too... trickier. Have you tried just using UTC dates? (ToUniversalTime/ToLocalTime).
Marc Gravell
Can I have some help on it UTC dates and DataSet ??
A: 

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;
            }
        }
Harish