DataGrid Update Problem

  • Thread starter Thread starter Reney
  • Start date Start date
R

Reney

I haven't used the VS Studio's drag&drop method to create my connection,
adapters and datasets, but I typed them all. The situation is like this:

There is a listbox with members pulled from the database.(I am using an
access db). The user selects one value from the listbox and clicks on one of
two buttons "ThisWeek" or "LastWeek". The button click events each has its
own SQL statement, pulling datarows from two different tables in the
database(they are related with "employeeID", which is selected in the
listbox I told before). Then the data adapter fills the dataset and it's
connected to one datagrid. The datagrid shows the values if the click event
completes successfully. But as I say, all the database connection, filling
and close processes are done in the click event.

The problem starts right after that. The user has the choice to modify the
dataset using the datagrid. And to update, he has to click on the "Update"
button in the form. But I don't kow how to make the update in antoher click
event. Since the datasets are created and tied to the grid in a different
click event. Now in another click event, the dataset is not recognized. So I
have to fill a new dataset, but this time, how is it going to recognize the
changes made to the dataset.

I am not very familiar with datagrids and datasets, so the topic is a little
bit out of my scope. After I looked through the Internet and forums, in all
the similar problems, they have a common thing that, they were filling the
dataset in the form_load events with simple sql statements. In my case, the
sql statement is dynamically changing with the value selected in a listbox
and the button pressed(Remember two buttons, "thisweek" and "lastweek"). And
the dataset is filled in a click event of one button. And update should be
in another click event of another button.

I hope I could explained my problem clearly. Any help would be highly
appreciated. Thanks for your time and comments in advance,
Reney
 
If I undertstand youre problem correctly . . .

You need to declare your dataset, dataadapter and connections as class (
Form ) members, this way you can alter them from any click event. These can
be called during initialisation and your datasets populated diring
form_load.

If I have misunderstood you, please clarify

Regards
 
Thanks for the quick response One Handed Man. I have corrected my problem by
referencing your message.

I have a new question now though. The sql statement that I was using in my
adapter was a join query, involving two tables, which have parent/child
relation. Now I learnt that, if the dataadapter's select command references
more than one table, the commandbuilder won't work. So what is the best
solution for this situation? Could you recommend me any sites that have
sample solutions for such situations.

Thanks in advance for your responses.
Reney
 
Thanks for the quick response One Handed Man. I have corrected my
problem by
referencing your message.

I have a new question now though. The sql statement that I was using in
my
adapter was a join query, involving two tables, which have parent/child
relation. Now I learnt that, if the dataadapter's select command
references
more than one table, the commandbuilder won't work. So what is the best
solution for this situation? Could you recommend me any sites that have
sample solutions for such situations.

Thanks in advance for your responses.
Reney
 
Back
Top