kvnsdr
asked on
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.Tab leName);
dsCustom.dt1 = temp.Copy(); // Error: Property or indexer cannot be assigned to -- it is read only
}
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.Tab
dsCustom.dt1 = temp.Copy(); // Error: Property or indexer cannot be assigned to -- it is read only
}
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);
// Clear out the existing data:
dsCustom.dt1.Clear;
// Impory the roes from temp - assuming the schema is the same
dsCustom.dt1.Mergs(temp);
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
}
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
}
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;
}
}
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;
}
}
ASKER
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?
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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);
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);
"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.
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.
ASKER
Cool, thanks...
Is Form1 actually writing to dt1 in the same way as copyTable() does? Cause that shouldn't work either...