Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 524
  • Last Modified:

Custom DataSet Class Read Only From Another Class?

I cannot write to my custom Dataset class from another class, however Form1 can.

The error message states the dataset/table is Read-Only!

Help......

[another.cs]
private dsCustom dsCustom; // Need this statement to use any table within the dataset

void copyTable()
{
     DataTable temp = new DataTable();
     dataView1.ToTable(temp.TableName);
     dsCustom.dt1 = temp.Copy();  // Error: Property or indexer cannot be assigned to -- it is read only      
}
0
kvnsdr
Asked:
kvnsdr
  • 3
  • 3
  • 2
  • +1
1 Solution
 
DelTremeCommented:
It seems that dt1 does not have a setter. If it was Private, the error message would have been "dt1 is inaccessible due to its protection level".

Is Form1 actually writing to dt1 in the same way as copyTable() does? Cause that shouldn't work either...
0
 
dstanley9Commented:
You can't override the value of the dt1 property, but you can import the data:

// Clear out the existing data:
dsCustom.dt1.Clear;
// Impory the roes from temp - assuming the schema is the same
dsCustom.dt1.Mergs(temp);

0
 
udhayakumardCommented:
Hi,

Is dt1 is a member.property in Custom DataSet Class... If so, then u have to give both the set and get property.

Ex:

public DataTable dt1
{
       get
       {
                 return this.dt1;
        }

       set


}
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
udhayakumardCommented:
Hi,

Is dt1 is a member.property in Custom DataSet Class... If so, then u have to give both the set and get property.

Ex:

public DataTable dt1
{
       get
       {
                 return this.dt1;
        }

       set
       {

                this.dt1 = value;
       }

}
0
 
kvnsdrAuthor Commented:
I made DataSet 'dsCustom' using drag-n-drop from Form1 and created my own tables.

VS2005 'Solution Explorer' shows 'dsCustom.xsd'

Maybe I should have created the dataset another way so it's easily accessable by all forms and classess?
0
 
dstanley9Commented:
It's accessible - but dt1 is referencing a DataTable object within the DataSet class, and doesn't need to be "set", you just need to get data into it.  That's standard practice for typed datasets.  
0
 
kvnsdrAuthor Commented:
Yep, it was mark private and I used this code to make it work.

I found that 'Merge' method has both Get & Set, where 'Copy' has only Get...
 
DataTable temp = dataView.ToTable();
dsCustom = new dsCustom();                    
dsCustom.dt1.Merge(temp);
0
 
dstanley9Commented:
"I found that 'Merge' method has both Get & Set, where 'Copy' has only Get"

It's the dt1 property that only has a Get accessor.  When VS creates a typed DataSet, it creates a read-only property for each table - in your case dt1.  The property is just a reference to an existing datatable, and that reference cannot be changed.  That doesn't mean that the _table_ is read-only, just the property that references that table.  Meaning that you can't set the property to a whole new table object, but you can add data and manipulate the _existing_ table.  
0
 
kvnsdrAuthor Commented:
Cool, thanks...
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 3
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now