DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Fri, 17 Aug 2007 08:36:01 -0700,    posted on: microsoft.public.dotnet.framework.adonet        back       

Thread Index
  1    David
          2    Manish Bafna
                 3    David
                        4    Manish Bafna


What sort of dataset is it?   
I have an application that saves a bunch of data in XML files that come from 
typed datasets.

So, I have something like this:

MyTypedDs  myds;

//.... When the user wants to save the data

myds.WriteXML(thefilename,XMLWriteMode.WriteSchema);

Later on, when he wants to open a saved file,

myds=new (MyTypedDs);
myds.ReadXML(thefilename,XMLReadMode.ReadSchema);



Great.  So far, so good.

Now, some fields have been added to the records.  The tables in the dataset 
have some additional columns.  I want to be able to open up the old files 
that have been previously saved, and if the file is from the old format, 
convert it to the new format, filling in default values for missing fields.

TypedDSV1 myversion1ds;
TypedDSV2 myversion2ds;

DataSet myds;

//When opening a file.

     myds.ReadXML(thefilename,XMLReadMode.ReadSchema)
    if (the schema from the file matches version1)
       {myversion1ds=(TypedDSV1)myds;
         Convertv1tov2(myversion1ds,myversion2ds);
        }
    else if (the schema from the file matches version 2)
    {
        myversion2ds=(TypedDSV2)myds;
    }
   else return retvals.Schemadoesntmatch;

So, is there a very easy way to write the (the schema from the file matches 
version 2) function?
Date:Fri, 17 Aug 2007 08:36:01 -0700   Author:  

RE: What sort of dataset is it?   
Hi,
you can try something like this in below sample code:
private void Form1_Load(object sender, EventArgs e)
        {
            
            DataTable dt = new DataTable();
            DataColumn col1 = new DataColumn();
            DataColumn col2 = new DataColumn();
            col1.ColumnName = "Name";
            col2.ColumnName = "PostingTime";
            
            col1.DataType = typeof(System.String);
            col2.DataType = typeof(System.DateTime);
            dt.Columns.Add(col1);
            dt.Columns.Add(col2);
          
            DataRow row1 = dt.NewRow();
            row1["Name"] = "Manish Bafna";
            row1["PostingTime"] = DateTime.Now;

            DataRow row2 = dt.NewRow();
            row2["Name"] = "Sanjay Bafna";
            row2["PostingTime"] = DateTime.Now.AddHours(5);

            dt.Rows.Add(row1);
            dt.Rows.Add(row2);

            dt.AcceptChanges();

            DataSet ds = new DataSet();
            ds.Tables.Add(dt);
           
            ds.WriteXml("XMLFile1.xml", XmlWriteMode.IgnoreSchema);

            dataGridView1.DataSource = dt;

            DataColumn col3 = new DataColumn();
            col3.ColumnName = "NewColumn";
            col3.DataType = typeof(System.String);
            col3.DefaultValue = "Hello";
            ds.Tables[0].Columns.Add(col3);
            DataRow row3 = ds.Tables[0].NewRow();

            row3["Name"] = "Janak NAIK";
            row3["PostingTime"] = DateTime.Now.AddYears(2);
            row3["NewColumn"] = "Welcome";
            ds.Tables[0].Rows.Add(row3);

            ds.AcceptChanges();

            DataSet ds2 = new DataSet();

            ds2.ReadXml("XMLFile1.xml", XmlReadMode.IgnoreSchema);

            ds.Merge(ds2, true, MissingSchemaAction.Ignore);

            dataGridView2.DataSource = ds.Tables[0];
        }

-- 
Hope this helps.
Thanks and Regards.
Manish Bafna.
MCP and MCTS.



"David" wrote:


> I have an application that saves a bunch of data in XML files that come from 
> typed datasets.
> 
> So, I have something like this:
> 
> MyTypedDs  myds;
> 
> //.... When the user wants to save the data
> 
> myds.WriteXML(thefilename,XMLWriteMode.WriteSchema);
> 
> Later on, when he wants to open a saved file,
> 
> myds=new (MyTypedDs);
> myds.ReadXML(thefilename,XMLReadMode.ReadSchema);
> 
> 
> 
> Great.  So far, so good.
> 
> Now, some fields have been added to the records.  The tables in the dataset 
> have some additional columns.  I want to be able to open up the old files 
> that have been previously saved, and if the file is from the old format, 
> convert it to the new format, filling in default values for missing fields.
> 
> TypedDSV1 myversion1ds;
> TypedDSV2 myversion2ds;
> 
> DataSet myds;
> 
> //When opening a file.
> 
>      myds.ReadXML(thefilename,XMLReadMode.ReadSchema)
>     if (the schema from the file matches version1)
>        {myversion1ds=(TypedDSV1)myds;
>          Convertv1tov2(myversion1ds,myversion2ds);
>         }
>     else if (the schema from the file matches version 2)
>     {
>         myversion2ds=(TypedDSV2)myds;
>     }
>    else return retvals.Schemadoesntmatch;
> 
> So, is there a very easy way to write the (the schema from the file matches 
> version 2) function?
Date:Fri, 17 Aug 2007 10:38:07 -0700   Author:  

RE: What sort of dataset is it?   
Thanks, although I was kind of hoping for a "compareschema" function.  It 
would seem useful.  I wonder why it doesn't exist.

I think that, instead, what I really need is to see if the two datasets have 
the same number of tables and same columns.  So, I think I'll write a utility 
that compares the columnames in each table.

"Manish Bafna" wrote:


> Hi,
> you can try something like this in below sample code:
> private void Form1_Load(object sender, EventArgs e)
>         {
>             
>             DataTable dt = new DataTable();
>             DataColumn col1 = new DataColumn();
>             DataColumn col2 = new DataColumn();
>             col1.ColumnName = "Name";
>             col2.ColumnName = "PostingTime";
>             
>             col1.DataType = typeof(System.String);
>             col2.DataType = typeof(System.DateTime);
>             dt.Columns.Add(col1);
>             dt.Columns.Add(col2);
>           
>             DataRow row1 = dt.NewRow();
>             row1["Name"] = "Manish Bafna";
>             row1["PostingTime"] = DateTime.Now;
> 
>             DataRow row2 = dt.NewRow();
>             row2["Name"] = "Sanjay Bafna";
>             row2["PostingTime"] = DateTime.Now.AddHours(5);
> 
>             dt.Rows.Add(row1);
>             dt.Rows.Add(row2);
> 
>             dt.AcceptChanges();
> 
>             DataSet ds = new DataSet();
>             ds.Tables.Add(dt);
>            
>             ds.WriteXml("XMLFile1.xml", XmlWriteMode.IgnoreSchema);
> 
>             dataGridView1.DataSource = dt;
> 
>             DataColumn col3 = new DataColumn();
>             col3.ColumnName = "NewColumn";
>             col3.DataType = typeof(System.String);
>             col3.DefaultValue = "Hello";
>             ds.Tables[0].Columns.Add(col3);
>             DataRow row3 = ds.Tables[0].NewRow();
> 
>             row3["Name"] = "Janak NAIK";
>             row3["PostingTime"] = DateTime.Now.AddYears(2);
>             row3["NewColumn"] = "Welcome";
>             ds.Tables[0].Rows.Add(row3);
> 
>             ds.AcceptChanges();
> 
>             DataSet ds2 = new DataSet();
> 
>             ds2.ReadXml("XMLFile1.xml", XmlReadMode.IgnoreSchema);
> 
>             ds.Merge(ds2, true, MissingSchemaAction.Ignore);
> 
>             dataGridView2.DataSource = ds.Tables[0];
>         }
> 
> -- 
> Hope this helps.
> Thanks and Regards.
> Manish Bafna.
> MCP and MCTS.
> 
> 
> 
> "David" wrote:
> 
> > I have an application that saves a bunch of data in XML files that come from 
> > typed datasets.
> > 
> > So, I have something like this:
> > 
> > MyTypedDs  myds;
> > 
> > //.... When the user wants to save the data
> > 
> > myds.WriteXML(thefilename,XMLWriteMode.WriteSchema);
> > 
> > Later on, when he wants to open a saved file,
> > 
> > myds=new (MyTypedDs);
> > myds.ReadXML(thefilename,XMLReadMode.ReadSchema);
> > 
> > 
> > 
> > Great.  So far, so good.
> > 
> > Now, some fields have been added to the records.  The tables in the dataset 
> > have some additional columns.  I want to be able to open up the old files 
> > that have been previously saved, and if the file is from the old format, 
> > convert it to the new format, filling in default values for missing fields.
> > 
> > TypedDSV1 myversion1ds;
> > TypedDSV2 myversion2ds;
> > 
> > DataSet myds;
> > 
> > //When opening a file.
> > 
> >      myds.ReadXML(thefilename,XMLReadMode.ReadSchema)
> >     if (the schema from the file matches version1)
> >        {myversion1ds=(TypedDSV1)myds;
> >          Convertv1tov2(myversion1ds,myversion2ds);
> >         }
> >     else if (the schema from the file matches version 2)
> >     {
> >         myversion2ds=(TypedDSV2)myds;
> >     }
> >    else return retvals.Schemadoesntmatch;
> > 
> > So, is there a very easy way to write the (the schema from the file matches 
> > version 2) function?
Date:Tue, 21 Aug 2007 11:26:01 -0700   Author:  

RE: What sort of dataset is it?   
Hi,
I think i have gone little bit off the topic.You can use use in-built 
GetSchema method of DataTable,Dataset or connection in your custom 
compareschema method.Google for Getschema and you will get further insights 
on how you can use in your compareschema method.It can be as simple as 
something like this:
If dataset1.GetSchema().Equals(dataset2.Getschema()
{
messagebox.show("Schema are equal");
}
else
{
messagebox.show("Schema are not equal");
}
-- 
Hope this helps.
Thanks and Regards.
Manish Bafna.
MCP and MCTS.



"David" wrote:


> Thanks, although I was kind of hoping for a "compareschema" function.  It 
> would seem useful.  I wonder why it doesn't exist.
> 
> I think that, instead, what I really need is to see if the two datasets have 
> the same number of tables and same columns.  So, I think I'll write a utility 
> that compares the columnames in each table.
> 
> "Manish Bafna" wrote:
> 
> > Hi,
> > you can try something like this in below sample code:
> > private void Form1_Load(object sender, EventArgs e)
> >         {
> >             
> >             DataTable dt = new DataTable();
> >             DataColumn col1 = new DataColumn();
> >             DataColumn col2 = new DataColumn();
> >             col1.ColumnName = "Name";
> >             col2.ColumnName = "PostingTime";
> >             
> >             col1.DataType = typeof(System.String);
> >             col2.DataType = typeof(System.DateTime);
> >             dt.Columns.Add(col1);
> >             dt.Columns.Add(col2);
> >           
> >             DataRow row1 = dt.NewRow();
> >             row1["Name"] = "Manish Bafna";
> >             row1["PostingTime"] = DateTime.Now;
> > 
> >             DataRow row2 = dt.NewRow();
> >             row2["Name"] = "Sanjay Bafna";
> >             row2["PostingTime"] = DateTime.Now.AddHours(5);
> > 
> >             dt.Rows.Add(row1);
> >             dt.Rows.Add(row2);
> > 
> >             dt.AcceptChanges();
> > 
> >             DataSet ds = new DataSet();
> >             ds.Tables.Add(dt);
> >            
> >             ds.WriteXml("XMLFile1.xml", XmlWriteMode.IgnoreSchema);
> > 
> >             dataGridView1.DataSource = dt;
> > 
> >             DataColumn col3 = new DataColumn();
> >             col3.ColumnName = "NewColumn";
> >             col3.DataType = typeof(System.String);
> >             col3.DefaultValue = "Hello";
> >             ds.Tables[0].Columns.Add(col3);
> >             DataRow row3 = ds.Tables[0].NewRow();
> > 
> >             row3["Name"] = "Janak NAIK";
> >             row3["PostingTime"] = DateTime.Now.AddYears(2);
> >             row3["NewColumn"] = "Welcome";
> >             ds.Tables[0].Rows.Add(row3);
> > 
> >             ds.AcceptChanges();
> > 
> >             DataSet ds2 = new DataSet();
> > 
> >             ds2.ReadXml("XMLFile1.xml", XmlReadMode.IgnoreSchema);
> > 
> >             ds.Merge(ds2, true, MissingSchemaAction.Ignore);
> > 
> >             dataGridView2.DataSource = ds.Tables[0];
> >         }
> > 
> > -- 
> > Hope this helps.
> > Thanks and Regards.
> > Manish Bafna.
> > MCP and MCTS.
> > 
> > 
> > 
> > "David" wrote:
> > 
> > > I have an application that saves a bunch of data in XML files that come from 
> > > typed datasets.
> > > 
> > > So, I have something like this:
> > > 
> > > MyTypedDs  myds;
> > > 
> > > //.... When the user wants to save the data
> > > 
> > > myds.WriteXML(thefilename,XMLWriteMode.WriteSchema);
> > > 
> > > Later on, when he wants to open a saved file,
> > > 
> > > myds=new (MyTypedDs);
> > > myds.ReadXML(thefilename,XMLReadMode.ReadSchema);
> > > 
> > > 
> > > 
> > > Great.  So far, so good.
> > > 
> > > Now, some fields have been added to the records.  The tables in the dataset 
> > > have some additional columns.  I want to be able to open up the old files 
> > > that have been previously saved, and if the file is from the old format, 
> > > convert it to the new format, filling in default values for missing fields.
> > > 
> > > TypedDSV1 myversion1ds;
> > > TypedDSV2 myversion2ds;
> > > 
> > > DataSet myds;
> > > 
> > > //When opening a file.
> > > 
> > >      myds.ReadXML(thefilename,XMLReadMode.ReadSchema)
> > >     if (the schema from the file matches version1)
> > >        {myversion1ds=(TypedDSV1)myds;
> > >          Convertv1tov2(myversion1ds,myversion2ds);
> > >         }
> > >     else if (the schema from the file matches version 2)
> > >     {
> > >         myversion2ds=(TypedDSV2)myds;
> > >     }
> > >    else return retvals.Schemadoesntmatch;
> > > 
> > > So, is there a very easy way to write the (the schema from the file matches 
> > > version 2) function?
Date:Tue, 21 Aug 2007 18:42:00 -0700   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us