Is DataSet ReadOnly?

G

Grzegorz Danowski

Hey everybody!



I have DataSet built basing on SQL string written in textbox by user (me),
then I connect the DataSet to DataGrid in so way:



data.PrepareDs(txtSql.Text);
myDs = data.ActData;
DataTable myDt = myDs.Tables["data"];
DataView myDv = new DataView(myDt);
this.myDataGrid.DataSource = myDv;



User has possibility to update data in the DataGrid. It's fine, but there is
problem when DataSet is read only (for example "Select Count(*) From
Table"). In so situation I would like to block any changes in DataGrid.

How can I test whether DataSet is read only?



Thanks for any help!

Grzegorz
 
D

Dmitriy Lapshin [C# / .NET MVP]

Hey Grzegorz,

You can block adding new rows and editing existing rows to the grid with the
following code:

myDv.AllowNew = false;
myDv.AllowEdit = false;
 
?

=?ISO-8859-2?Q?Marcin_Grz=EAbski?=

Hi/Cze¶æ Grzegorz,
Hey everybody!

I have DataSet built basing on SQL string written in textbox by user (me),
then I connect the DataSet to DataGrid in so way:

data.PrepareDs(txtSql.Text);
myDs = data.ActData;
DataTable myDt = myDs.Tables["data"];
DataView myDv = new DataView(myDt);
this.myDataGrid.DataSource = myDv;

User has possibility to update data in the DataGrid. It's fine, but there is
problem when DataSet is read only (for example "Select Count(*) From
Table"). In so situation I would like to block any changes in DataGrid.

How can I test whether DataSet is read only?

I'm affraid that only *You* (as a programmer) can define
read-only for your table.
*You* should know that your SQL-SELECT expression has be treated as a
table or as a calculated value.

Imagine that DataSet is only set of DataTables, an universal
collections which doesn't care of inserted values.
DataTable (e.g. in Fill method) treat any SELECT expression as
it is a table.

Regards

Marcin
 
G

Grzegorz Danowski

Marcin Grzêbski said:
Hi/Cze¶æ Grzegorz,

I'm affraid that only *You* (as a programmer) can define
read-only for your table.
*You* should know that your SQL-SELECT expression has be treated as a
table or as a calculated value.

Well. But when I tried update any not updateable DataSet I get exception:

"...Additional information: Dynamic SQL generation is not supported against
a SelectCommand that does not return any base table information."

Is there no possibility to find (in fast way, before update) that the
SelectCommand doesn't return any base table information?

Thanks

Grzegorz
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top