dataset problem

thomas008

Well-known member
Joined
Feb 17, 2009
Messages
54
Location
Belgium
Programming Experience
Beginner
I have an application that uses a dataset with custom validation.
When my application form is the startup form everything works fine.
The problem is this application needs to be part of a bigger one so i need
to be able to add it to the other one. When i add it it seems like there are 2 datasets. One that is loaded by my startupform and one that is used by the other form. How do i get them to use the same dataset?
 
can you give an example of what youre doing?

is the dataset created as a public shared dataset or a dimmed dataset on the form?

br

andy
 
I'm not really sure! Its a dataset build by the designer so i think its a public one. But i fixed the problem of the dataset. I refered to it in the dataset.vb file
as formname.dataset.datatabLe.rows but it had to be me.rows. The only problem i have now is that my datatimepickers do not give me the right values when my the form they are on is not the startup form
 
i dont know for sure, but it sounds like they are bound to the startup form's instance of the dataset? try checking some datetimes by row on the startform then looking at the data on your other form to see if the dates are using the startup form's data?
 
I think you are on to something. When i check the values of the datetimepicker they always give me the time when the application started to run and not the time it changed to. I'm not sure where i need to change this?
 
I think you are on to something. When i check the values of the datetimepicker they always give me the time when the application started to run and not the time it changed to. I'm not sure where i need to change this?

are they within thr datagrid cells in a template or outside as seperte controls?

can u show me yyour binding code?
 
They are outside as seperate controls and the bindingcode is standard vb generated code. I just selected the datetimepickers from the dataset in the datasources tab
 
They are outside as seperate controls and the bindingcode is standard vb generated code. I just selected the datetimepickers from the dataset in the datasources tab

what about trying a rebind on the form load event then as they sound like theyre on the old source...
 
I tried what you said but i'm not sure if i did it right. The datetimepicker did not change at all after i did it. I just think somehow the reference that i use in the dataset.vb file is wrong. the form where the datetimepickers are on is called db
So i just use DB.datetimepicker.value but it always gives me the value of when i started the program and not the one that my messagebox gives me when the valuechanged event is raised.
 
Maybe i should explain my problem a bit more. I have a form which handles my database access, lets call it DB. On this form i have a bindingsource, a tableadapter, a dataset and a bindingnavigator. When double clicking the dataset you see the table and all its fields and the defined querys. now when you click one of the fields the datasets .vb file opens and you can add custom validation. I added my validation in the columnchanging event. Now when the event is fired and one of the datetimecolumns are changed i need to know the values of 2 datetimepickers in the DB from.

VB.NET:
If DB.BeginDatumTijdDateTimePicker.Value >= DB.EindDatumTijdDateTimePicker.Value Then
                e.Row.SetColumnError("BeginDatumTijd", "BeginTijd mag niet groter of gelijk zijn aan EindTijd")
            Else

                If e.Column Is Me.BeginDatumTijdColumn Then
                    checkBeginDatumTijd(e.Row)
                    checkBeginDateTime(e.Row)
                    checkEindDateTime(e.Row)
                End If

                If e.Column Is Me.EindDatumTijdColumn Then
                    checkEindDatumTijd(e.Row)
                    checkEindDateTime(e.Row)
                    checkBeginDateTime(e.Row)
                End If

            End If

When the startingtime is bigger or equal to the endingtime it should bother
validating because it is wrong anyway so i just set the rowerror.

Now when the DB form is the startupform everything works fine. But this is just a small part of my application so it will not be the startupform. When another form is the startupform the 2 datetimepickers contain the date and time of when the form started so they are equal which results in a rowerror.

When i check the values in the DB form they are displayed fine but when i use the code above in the dataset.vb file they are not.

I tried to set the modifier of the datetimepickers to public but that didn't help.

Is there another way to reference the datetimepickers then the way i did?
Or am i doing something wrong here?

I hope my explanation was clear.
Thanks in advance
 
it just sounds like youre completely confused as to what to put where, and what part of your program does what. If you must constrain the values entered into a dataset to a certain range, you should do this in the dataset itself so that data cannot be admitted outside of the range. Further, you shouldnt be referencing datetimepickers from such code, because the dataset isnt supposed to know about datetimepickers or presentational aspects..

have a read of Walkthrough: Adding Validation to a Dataset
 
Well i know this is not the way it is suposed to be done but i didn't know what other way to do it. The datetimepickers are used to enter timeintervals. The dataset already contains some intervals. So i need to check whether one of the values currently in the datetimepickers is in between one of the existing intervals and if the timeinterval the user wants to enter isn't to big so the others get overlapped. Now i'm thinking i should have used the rowchanging event instead of the columnchanging event.
 
Ok i found something that works. I hope its the right way!

I'm using the columnchanging event. When one of the datetime columns changes i get the value of the changing column by using
VB.NET:
e.ProposedValue
now i need the get the value of the other datetime column. For this i'm using
VB.NET:
e.Row.Item("nameofthecolumn")

Atleast this code works. Could anyone tell me if this is the right way to do it?
 

Latest posts

Back
Top