newbie question - DataSet chemistry vs manual workaround

  • Thread starter Thread starter Sergei Shelukhin
  • Start date Start date
S

Sergei Shelukhin

Hi. I just started out with .NET, andt I have this question... I need to
display complicated set of data in the datagrid.
When I display it by getting appropriate query into the data adapter (query
is like "SELECT *,CAST(DATEPART(HH, r.dt1) AS char(2))+':'+CAST(DATEPART(mi,
r.dt1) AS char(2)) sdt1,CAST(DATEPART(HH, r.dt2) AS
char(2))+':'+CAST(DATEPART(mi, r.dt2) AS char(2))
sdt2,DATEDIFF(mi,r.dt1,r.dt2) tspan,(SELECT SUM(RA.Value*A.importance) FROM
RecordArea RA,Area A WHERE (RA.AreaId = A.AreaId) AND (RA.RecordId =
r.RecordId ) ) usef FROM record r LEFT OUTER JOIN Category ON (r.categoryid
= category.categoryid) WHERE dayid = (SELECT dayid FROM day WHERE rdate =
(SELECT MAX(rdate) FROM day WHERE status = 0) )" and growing), it is not
available for auto editing - cmponents' don't seem to recognise that it is
in fact Record table and some stuff around it :)


When I try to add InsertCommand & UpdateCommand to data adapter, it seems to
be ok, and it runs Update method without any errors but nothing is updated.
I also tried calling AcceptChanges for dataset and table itself before
adapter update, and it didn't help either.
I settled with updating manually with values taken out of databound
textboxes and such.

On the other hand i have learned that unlike for example BCB TQuery that is
plain, DataSet in .NET can include multiple tables, relations and other
things like that; if I had those, I could update everything automatically;
but then, how do I get this complicated thing into the DataGrid? Is there
any way to link things together and make DataAdapter "understand" what is
what?

And btw what is the right approach widely used for professional apps anyway?
;)
I remember back in BCB original controls like TTable were not any effective
so I used manually constructed and launched queries for any more or less
complicated data operations, using TTable & TQuery bound to DBGrid (analogue
of DataGrid there) only for display...
 
Sergei Shelukhin said:
Hi. I just started out with .NET, andt I have this question... I need to
display complicated set of data in the datagrid.
When I display it by getting appropriate query into the data adapter (query
is like "SELECT *,CAST(DATEPART(HH, r.dt1) AS char(2))+':'+CAST(DATEPART(mi,
r.dt1) AS char(2)) sdt1,CAST(DATEPART(HH, r.dt2) AS
char(2))+':'+CAST(DATEPART(mi, r.dt2) AS char(2))
sdt2,DATEDIFF(mi,r.dt1,r.dt2) tspan,(SELECT SUM(RA.Value*A.importance) FROM
RecordArea RA,Area A WHERE (RA.AreaId = A.AreaId) AND (RA.RecordId =
r.RecordId ) ) usef FROM record r LEFT OUTER JOIN Category ON (r.categoryid
= category.categoryid) WHERE dayid = (SELECT dayid FROM day WHERE rdate =
(SELECT MAX(rdate) FROM day WHERE status = 0) )" and growing), it is not
available for auto editing - cmponents' don't seem to recognise that it is
in fact Record table and some stuff around it :)

Yes, there is almost 100% guarantee that this isn't going to lend itself
well to automatic code generators. The select statement will work, but it
would be amazing if this worked for update/insert/delete.

The combination of fields that you are doing, with the Casts coupled with
concatenation would probably be a lot easier to implement on the whole if
you used expression columns for the concatenation.
http://www.knowdotnet.com/articles/expressions.html
When I try to add InsertCommand & UpdateCommand to data adapter, it seems to
be ok, and it runs Update method without any errors but nothing is
updated.
I don't think it will ever work as indicated above. To be sure, check out
the code that it generates for your Update and Insert commands. That will
give you a hint to waht's being submitted
I also tried calling AcceptChanges for dataset and table itself before
adapter update, and it didn't help either.

Don't ever call AcceptChanges before Update unless you don't want to changed
rows to be sent back to the db for somereason. If you call .AcceptChanges
in the line immediately preceding the Update method call, you will be 100%
sure that nothing will be sent back to the db ...
http://www.knowdotnet.com/articles/efficient_pt4.html


I settled with updating manually with values taken out of databound
textboxes and such.

On the other hand i have learned that unlike for example BCB TQuery that is
plain, DataSet in .NET can include multiple tables, relations and other
things like that; if I had those, I could update everything automatically;
but then, how do I get this complicated thing into the DataGrid? Is there
any way to link things together and make DataAdapter "understand" what is
what?

You can bind the grid's datasource property to a dataset or a datatable.
You can adjust your bindings like ValueMember and DisplayMember
 
Umm... Apart from generally used approach question, nevermind ;)

There was a flaw in my code.
 
Back
Top