473,385 Members | 1,402 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Refresh DataSet - please Help Me :-(

I GIVE UP...I can't refresh datagrid (dataset)

I have datagrid = dgrPaczki
Datasource of that datagrid = DataSetPaczki1.PACZKI_PAKOWALNIA (forgive me Polish words)
Dataadapter which fills my DataSetPaczki1 = adaPaczki
Dataadapter selects rows returned by user defined function = PACZKI_Z_AKCJI
To select rows from that function it uses sqlCommand = comPaczki

I will explain how it works:

First : sqlCommand (comPaczki):
Me.comPaczki = New System.Data.SqlClient.SqlCommand
Me.comPaczki.Connection = Me.SqlConnection1
Me.comPaczki.Parameters.Add(New System.Data.SqlClient.SqlParameter("@AKCJA_ID",... ..Int,..., "0"))
Me.comPaczki.Parameters.Add(New System.Data.SqlClient.SqlParameter("@DATA_OD",...S mallDateTime.., ""))
Me.comPaczki.Parameters.Add(New System.Data.SqlClient.SqlParameter("@DATA_DO",...S mallDateTime.., ""))

Dim strSQL As String - (this is SelectCommand for DataAdapter)
strSQL = "SELECT * FROM " & "PACZKI_Z_AKCJI" & "(@AKCJA_ID,@DATA_OD,@DATA_DO)"
When I click button then dataadapter fills dataset:

Me.adaPaczki.SelectCommand = Me.comPaczki

Me.comPaczki.Parameters(0).Value = cmbAkcja.SelectedValue
Me.comPaczki.Parameters(1).Value = datOd.Value
Me.comPaczki.Parameters(2).Value = datDo.Value

DataSetPaczki1.PACZKI_PAKOWALNIA.Clear()
adaPaczki.Fill(DataSetPaczki1, "PACZKI_PAKOWALNIA")
(and then is code for tablestyle - which hides some columns, changes size of colums... but I think it is not a problem)

-------------------------------------------
NOW WILL BE A PROBLEM
-------------------------------------------

Everything works fine - I can hit the button and datagrid shows always rows.
I can change the parameters from comPaczki (for example startDate and endDate).
And it always fills the datagrid.

But...

I have command which allows user to add new row to SQL database.
It works also fine. No errors.
When I check in MS SQL - new row is added.

But...

After that I clear DataSet.
DataSetPaczki1.PACZKI_PAKOWALNIA.Clear()

Then I fill dataadapter again.
adaPaczki.Fill(DataSetPaczki1, "PACZKI_PAKOWALNIA")

And it shows old rows!!
:-(

Why...? Why... :-(

Please help me.
I am wasting third day for that.
I have checked so many pages and forums...
No solution.
Nov 21 '05 #1
12 7927
Chreo,

Can you try to set after your fill the datagrid.datasource = nothing and
than again
datagrid.datasource = DataSet.packets.gluepackets

Cor
Nov 21 '05 #2
Ok... I did it...
But still is the same problem.

But I found something.
I had only one dataadapter.
I added second dataadapter.

And after adding a row to database I use second dataadapter to fill dataset.
But when I add another row to database and use again second dataadapter then
it doesn't work.

So I still have a problem,
I can add 1000 dataadapters to my form and after every change in database
use another dataadapter. :)

Maybe I can delete everytime the same dataadapter and create it again?
I am trying to do this but it doesn't work.

Is it possible that old values (old rows) are saved in dataadapter?
I thought that rows are saved in some other place (dataset?)
But I wrote that earlier - even if I cleat dataset - old rows come back.
But if I use new dataadapter to fill dataset - it works...

BUT HOW TO USE THE SAME DATAADAPTER EVERYTIME? :-(
Użytkownik "Cor Ligthert" <no************@planet.nl> napisał w wiadomo¶ci
news:uy**************@TK2MSFTNGP10.phx.gbl...
Chreo,

Can you try to set after your fill the datagrid.datasource = nothing and
than again
datagrid.datasource = DataSet.packets.gluepackets

Cor

Nov 21 '05 #3
Chreo,

You write first SQL command. Are you maybe adding more parameters than you
think and therefore is it with the second fill parameter 4,5,6 etc, while
1,2 and 3 are still unchanged?

Just a thought,

Cor
Nov 21 '05 #4
It is not problem with adding paramters, because they are added only on
begining and after that only values of parameters change.

I found something mysterious, but when I find out where is the reason then
maybe I solve my problem...
Read this:

I don't need to add new dataadapter to fill datagrid after adding new row.

I can use one dataadapter and add new row, and then another...and another...

But after about 20-25seconds I can't add any rows :(

Is it some timeout?
In which control?
Nov 21 '05 #5
Chreo,

I looked what more at your code.
I never did it that way so I am guessing.

You are forever filling 4 tables.
From which one is that packet one.
Than you clear from the dataset that packet one
fill the packet one
And refill the others again
Than you clear from the dataset that packet one
fill the packet one
And refill the others again

(I use for every table in this case another adapter)

Is that what you are up to?

Cor
Nov 21 '05 #6
Cor Ligthert - You are the only one who tries to help me.
Thanx.
But my problem is so weird so even I don't know what is going on.

I cut my code and now is only one adapter which fills DataSet everytime
(after adding row)

But I don't know why everything works only 15 seconds (I think that is
timeout of SQLConnection).
If I add 5 times new row (every row in 3seconds) then all 5 rows are added
to datagrid.
After 15 second I still add new rows but only to database (they don't appear
in datagrid)

But where is the reason :(
I dispose dataadapter and add it again after new rows.
I do it also with my command which selects rows.

I am still looking for that timeout.
Where it can be?
Nov 21 '05 #7
Chreo,

It is weird as you say. In your situation would I make a very simple program
that simulates what you do with only those essentials. And than try that.
When you than still have problems you show that, what makes it easier to
help you as well.

And than to get more help it probably better to ask this in the newsgroup

Adonet
news://msnews.microsoft.com/microsof...amework.adonet

Web interface:
http://communities2.microsoft.com/co...amework.adonet

With this not telling you to leave here, I am active in that newsgroup as
well.

However when you dump it in with the documentation as your problem is now,
do I give you not much change, however you can try that as well first (what
I would not do, I would make first that little test program. There is much
more change on help when it is easy to understand).

Cor
Nov 21 '05 #8
On Fri, 1 Apr 2005 08:04:56 +0200, "Cor Ligthert"
<no************@planet.nl> wrote:
Chreo,

It is weird as you say. In your situation would I make a very simple program
that simulates what you do with only those essentials. And than try that.
When you than still have problems you show that, what makes it easier to
help you as well.

And than to get more help it probably better to ask this in the newsgroup

Adonet
news://msnews.microsoft.com/microsof...amework.adonet

Web interface:
http://communities2.microsoft.com/co...amework.adonet

With this not telling you to leave here, I am active in that newsgroup as
well.

However when you dump it in with the documentation as your problem is now,
do I give you not much change, however you can try that as well first (what
I would not do, I would make first that little test program. There is much
more change on help when it is easy to understand).

Cor


Firstly let me say I agree with Cor, the best approach to a problem
like this is to reduce it to a very simple problem and then add
complexity and see where it goes wrong.

Secondly, the usual approach to refreshing a dataset is to have one
dataadapter and use it to fill your base dataset.

When you want to refresh it

1) Update the database with any changes made.
2) accept changes
3) create a second dataset and fill that with what has changed in the
database, ideally using a timestamp type field.
4) merge this dataset into your original dataset, .Net will then
produce a single dataset.
5) If you need to identify what has changed you can do that as well
with the appropriate calls.

Doug Taylor

Nov 21 '05 #9
Doug,
Secondly, the usual approach to refreshing a dataset is to have one
dataadapter and use it to fill your base dataset.

Are you sure of that, I never saw it. As well does the designer not directly
take this choose in my opinion and when you use it won't create the update
statements for you.

I only use the designer to test something so I am not so sure.

Cor


Nov 21 '05 #10
On Fri, 1 Apr 2005 13:14:45 +0200, "Cor Ligthert"
<no************@planet.nl> wrote:
Doug,
Secondly, the usual approach to refreshing a dataset is to have one
dataadapter and use it to fill your base dataset.
Are you sure of that, I never saw it. As well does the designer not directly
take this choose in my opinion and when you use it won't create the update
statements for you.


I'm probably wrong as I don't normally use datatables, I prefer the
business objects approach, but we won't get into arguments over that,
in my experience the dataadaptor creates one dataset which may contain
multiple tables, and multiple command objects one for select, insert,
update and delete, which it attaches to the dataadaptor command set.

Sure if you throw another table on it will create another dataadapter,
but it would be better to alter the schema for the dataset and have
them all handled together. So you have the model dataadapter is the
bottom layer handling the connection and commands and the dataset
handles the data and interaction with the GUI.

I personally don't like the automatically created statements and tend
to roll my own or more likely use stored procedures, that way you can
separate the maintenance of the statements from your app code.

Conceptually the dataset is a remote copy of your database and is an
extremely powerful object almost a full RDBMS in its own right and the
ability to extract subsets of a database, i.e. all values that have
changed since the last accept changes, rollback and merge with an
equivalent or almost equivalent dataset greatly reduce the amount of
code you need to write
I only use the designer to test something so I am not so sure.

Cor


Nov 21 '05 #11
Dough,

I'm probably wrong as I don't normally use datatables, I prefer the
business objects approach, but we won't get into arguments over that,
in my experience the dataadaptor creates one dataset which may contain
multiple tables, and multiple command objects one for select, insert,
update and delete, which it attaches to the dataadaptor command set.


Do you have for me maybe an update SQL string as samples that updates 4
tables with one dataadapter in one time. It looks interesting to me.

I self have the approach that I use one dataadapter and change the commands,
however that is almost in my opinion the same as using more dataadapters.

Therfore I am very curious to your solution.

Cor
Nov 21 '05 #12
On Fri, 1 Apr 2005 17:19:02 +0200, "Cor Ligthert"
<no************@planet.nl> wrote:
Dough,

I'm probably wrong as I don't normally use datatables, I prefer the
business objects approach, but we won't get into arguments over that,
in my experience the dataadaptor creates one dataset which may contain
multiple tables, and multiple command objects one for select, insert,
update and delete, which it attaches to the dataadaptor command set.

Do you have for me maybe an update SQL string as samples that updates 4
tables with one dataadapter in one time. It looks interesting to me.

I self have the approach that I use one dataadapter and change the commands,
however that is almost in my opinion the same as using more dataadapters.


I didn't make myself clear, unless you are using a DB like Oracle 8 or
above where you can write update commands that span tables, you will
need to either have multiple command objects and switch them, or
multiple dataadaptors or change the commandtext of the command
objects, it is fairly trivial to write stored procedures that update
multiple tables, at least it is with Oracle's Pl/SQL or Java, I don't
know enough about SQL Server to comment there.

Sorry if I've mislead you.
Therfore I am very curious to your solution.

Cor


Nov 21 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Alex Bibiano | last post by:
I have a typed dataset in my WinForm and a textbox with databinding to the dataset (all without code). Now, in a button event, I assign a new dataset (retrieved from a function) to the dataset a...
1
by: Jason Huang | last post by:
Hi, On my C# windows from, I have some TextBoxes in a GroupBox. I have no problem to show data from a DataSet to these TextBoxes. However, I don't know how to refresh the GroupBox or TextBoxes...
7
by: Juan Romero | last post by:
Hey guys, please HELP I am going nuts with the datagrid control. I cannot get the damn control to refresh. I am using soap to get information from a web service. I have an XML writer output...
10
by: jaYPee | last post by:
I have a function that call a stored procedure which performs an insert command. now i want to refresh the dataset so that the newly inserted data will be available to my datagrid I have tried...
1
by: hcs | last post by:
Hello, on a datagrid when you alter the dataset and want to show the new dataset you use datagrid.refresh(). how is this possible on a form which is based on a dataset and consists of a number...
0
by: thomasp | last post by:
This is a two part question, 1) The code below should display a form with a datagridview and a few command buttons. This form should allow the user to make change to the records displayed in...
3
by: david | last post by:
I do not have the experience with it. For example, update the data in the ASP form every minute by retrieving data from database. Or do you have other methods? Thank you for any advice and...
7
by: Randy | last post by:
Hi, I've got a listbox on a form that gets updated by opening another form for data entry. Once the user enters the new item name and clicks "accept", the data entry form closes and the original...
6
by: =?Utf-8?B?TWFyaw==?= | last post by:
Hi - I'm having trouble refreshing a datagrid control bound to a dataset that was created from the New Data Source wizard. What is the code required to refresh the datagrid with data from the...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.