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      
}
LVL 1
kvnsdrAsked:
Who is Participating?
 
dstanley9Connect With a Mentor Commented:
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
 
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
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
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
 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.