473,714 Members | 4,502 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Passing dataset by reference to another form

Hello there I was wondering if anyone could help me,

I am trying to pass a typed dataset to a dialoged child form by reference.
I have binding sources sitting on the child form. So to refresh them I just
set their datasource. I am guessing this is probably what is causing the
problem. Is there a better way to do this?

Anyway this all works happily and things show up when the record already
exists but I have 2 problems ;
1) When I add a new row it doesnt seem to create a record correctly (its not
there when I look at the watch, but the count increases)
2) When the record already exists and I edit it the datagrid on the main
form doesnt update with any data :(

Here is my constructor code;
Public Sub New(ByVal theDs As myTypedDatast, ByVal createNew As Boolean,
Optional ByVal theMaterialId As Integer = -1, Optional ByVal theServiceId As
Integer = -1)
Me.new()
'Refresh the bindings
Me.BaseDs = theDs
Me.bsCostCodes. DataSource = Me.BaseDs
Me.bsVendor.Dat aSource = Me.BaseDs
Me.bsTransactio ns.DataSource = Me.BaseDs

If createNew Then
'MessageBox.Sho w(tblTransactio ns.Count)
bsTransactions. AddNew()
'MessageBox.Sho w(tblTransactio ns.Count))
CurrentTransact ion.CostCode_Ty pe = "M"
CurrentTransact ion.ServiceID = theServiceId
CurrentTransact ion.CreatedBy = myBlSingleton.c urrentUser.user ID
CurrentTransact ion.CreatedOn = Now()
CurrentTransact ion.LastModifie dBy = myBlSingleton.c urrentUser.user ID
CurrentTransact ion.LastModifie dOn = Now()
CurrentTransact ion.Transaction _Date = Now()
Else
tblTransactions .Find("seqNum", theMaterialId)
CurrentTransact ion.LastModifie dBy = myBlSingleton.c urrentUser.user ID
CurrentTransact ion.LastModifie dOn = Now()
End If

End Sub

Private Function CurrentTransact ion() As BMS.BL.dsBMS.tb lTransactionsRo w
If tblTransactions .Current IsNot Nothing AndAlso TypeOf
tblTransactions .Current.row Is BMS.BL.dsBMS.tb lTransactionsRo w Then
Return CType(tblTransa ctions.Current. row, BMS.BL.dsBMS.tb lTransactionsRo w)
Else
Return Nothing
End If
End Function

Thank you kindly
John Sheppard
Jun 27 '08 #1
4 5925
John,

Do you expect to get any message (whatever you write later that a message
was very helpfull), to what you wrote.

I have spent some time on it, but I don't see any passing by reference, I
see all kind of objects it seems falling from air as me.bsCostCode, from
which I can think that it is a BindingSource however maybe something
complete different.

Try to make a little example from what you are doing not just passing in
your code, what is far from complete (and nobody is interested to analyse
your complete code than beginners who want to learn from it)

Not very helpful, but I hope it brings you in the right direction to make it
able for us to help you.

Cor

"John Sheppard" <sp**@nospam.co mschreef in bericht
news:fu******** *@news2.newsguy .com...
Hello there I was wondering if anyone could help me,

I am trying to pass a typed dataset to a dialoged child form by
reference. I have binding sources sitting on the child form. So to refresh
them I just set their datasource. I am guessing this is probably what is
causing the problem. Is there a better way to do this?

Anyway this all works happily and things show up when the record already
exists but I have 2 problems ;
1) When I add a new row it doesnt seem to create a record correctly (its
not there when I look at the watch, but the count increases)
2) When the record already exists and I edit it the datagrid on the main
form doesnt update with any data :(

Here is my constructor code;
Public Sub New(ByVal theDs As myTypedDatast, ByVal createNew As Boolean,
Optional ByVal theMaterialId As Integer = -1, Optional ByVal theServiceId
As Integer = -1)
Me.new()
'Refresh the bindings
Me.BaseDs = theDs
Me.bsCostCodes. DataSource = Me.BaseDs
Me.bsVendor.Dat aSource = Me.BaseDs
Me.bsTransactio ns.DataSource = Me.BaseDs

If createNew Then
'MessageBox.Sho w(tblTransactio ns.Count)
bsTransactions. AddNew()
'MessageBox.Sho w(tblTransactio ns.Count))
CurrentTransact ion.CostCode_Ty pe = "M"
CurrentTransact ion.ServiceID = theServiceId
CurrentTransact ion.CreatedBy = myBlSingleton.c urrentUser.user ID
CurrentTransact ion.CreatedOn = Now()
CurrentTransact ion.LastModifie dBy = myBlSingleton.c urrentUser.user ID
CurrentTransact ion.LastModifie dOn = Now()
CurrentTransact ion.Transaction _Date = Now()
Else
tblTransactions .Find("seqNum", theMaterialId)
CurrentTransact ion.LastModifie dBy = myBlSingleton.c urrentUser.user ID
CurrentTransact ion.LastModifie dOn = Now()
End If

End Sub

Private Function CurrentTransact ion() As BMS.BL.dsBMS.tb lTransactionsRo w
If tblTransactions .Current IsNot Nothing AndAlso TypeOf
tblTransactions .Current.row Is BMS.BL.dsBMS.tb lTransactionsRo w Then
Return CType(tblTransa ctions.Current. row,
BMS.BL.dsBMS.tb lTransactionsRo w)
Else
Return Nothing
End If
End Function

Thank you kindly
John Sheppard
Jun 27 '08 #2
Thanks Cor, sorry, yes after reading it again I realise it wasnt all that
clearly written. I also found an error (byVal was meant to be byRef). I
appoligies for such scrappy posting and I will try again; I very much
appreciate your time to have a look at it.

I have a parent form with the following property
Public myDataset as myTypedDataset

I have a parent form that runs the following code
dim myForm as new frmChildForm(my Dataset)
myForm.showdial og

I have a child form with the following constructor
Public Sub New(ByRef theDataset As myTypedDataset)
me.myBindingSou rce.datasource = theDataset
End Sub

So I have a few questions
1) Is this the correct/best way to be passing datasets to other forms? How
do other people do it? I have seen people passing binding sources?
2) I am having problems with bindings, when I add a new row it doesnt seem
to create a record correctly (its not there when I look at the watch, but
the count increases). Is there something else I have to do to make it rebind
all the controls properly?
3) When the record already exists and I edit it the datagrid on the main
form doesnt update with any data. Why would this be happening? When I look
at the watch the data is in the dataset.

Thank you
John
"Cor Ligthert[MVP]" <no************ @planet.nlwrote in message
news:10******** *************** ***********@mic rosoft.com...
John,

Do you expect to get any message (whatever you write later that a message
was very helpfull), to what you wrote.

I have spent some time on it, but I don't see any passing by reference, I
see all kind of objects it seems falling from air as me.bsCostCode, from
which I can think that it is a BindingSource however maybe something
complete different.

Try to make a little example from what you are doing not just passing in
your code, what is far from complete (and nobody is interested to analyse
your complete code than beginners who want to learn from it)

Not very helpful, but I hope it brings you in the right direction to make
it able for us to help you.

Cor

"John Sheppard" <sp**@nospam.co mschreef in bericht
news:fu******** *@news2.newsguy .com...
>Hello there I was wondering if anyone could help me,

I am trying to pass a typed dataset to a dialoged child form by
reference. I have binding sources sitting on the child form. So to
refresh them I just set their datasource. I am guessing this is probably
what is causing the problem. Is there a better way to do this?

Anyway this all works happily and things show up when the record already
exists but I have 2 problems ;
1) When I add a new row it doesnt seem to create a record correctly (its
not there when I look at the watch, but the count increases)
2) When the record already exists and I edit it the datagrid on the main
form doesnt update with any data :(

Here is my constructor code;
Public Sub New(ByVal theDs As myTypedDatast, ByVal createNew As Boolean,
Optional ByVal theMaterialId As Integer = -1, Optional ByVal theServiceId
As Integer = -1)
Me.new()
'Refresh the bindings
Me.BaseDs = theDs
Me.bsCostCodes .DataSource = Me.BaseDs
Me.bsVendor.Da taSource = Me.BaseDs
Me.bsTransacti ons.DataSource = Me.BaseDs

If createNew Then
'MessageBox.Sho w(tblTransactio ns.Count)
bsTransactions. AddNew()
'MessageBox.Sho w(tblTransactio ns.Count))
CurrentTransact ion.CostCode_Ty pe = "M"
CurrentTransact ion.ServiceID = theServiceId
CurrentTransact ion.CreatedBy = myBlSingleton.c urrentUser.user ID
CurrentTransact ion.CreatedOn = Now()
CurrentTransact ion.LastModifie dBy = myBlSingleton.c urrentUser.user ID
CurrentTransact ion.LastModifie dOn = Now()
CurrentTransact ion.Transaction _Date = Now()
Else
tblTransactions .Find("seqNum", theMaterialId)
CurrentTransact ion.LastModifie dBy = myBlSingleton.c urrentUser.user ID
CurrentTransact ion.LastModifie dOn = Now()
End If

End Sub

Private Function CurrentTransact ion() As BMS.BL.dsBMS.tb lTransactionsRo w
If tblTransactions .Current IsNot Nothing AndAlso TypeOf
tblTransaction s.Current.row Is BMS.BL.dsBMS.tb lTransactionsRo w Then
Return CType(tblTransa ctions.Current. row,
BMS.BL.dsBMS.t blTransactionsR ow)
Else
Return Nothing
End If
End Function

Thank you kindly
John Sheppard

Jun 27 '08 #3
John,
So I have a few questions
1) Is this the correct/best way to be passing datasets to other forms? How
do other people do it? I have seen people passing binding sources?
I seldom use by ref in fact I think never. It is only needed as you create a
new object in a child class.
In this case clearly not, be aware that passing reference types is always by
the value of its reference.
Therefore passing by value is also cheaper (but not more than I thought an
integer) than by reference.

I did never did it, but there can be in my idea not be any harm to pass the
bindingsource and use that in your child form control, but remember for
these kind as things, forever pass by value. However then you can of course
not add directly in your underlying dataset, what you do in my idea.

Be aware that you even can pass your datagridview on page one and by
casting, use the datasource of that and then again your bindingsource get
the underlying table. Something as (typed here not tested)

dim ds as DataSet =
DirectCast(Dire ctCast(myPassed DataGridView.Da taSource,Bindin gSource).DataSo urce,DataSet)
2) I am having problems with bindings, when I add a new row it doesnt seem
to create a record correctly (its not there when I look at the watch, but
the count increases). Is there something else I have to do to make it
rebind all the controls properly?
This is hard to answer as we don't know how you add a row, there are so many
methods for that.
3) When the record already exists and I edit it the datagrid on the main
form doesnt update with any data. Why would this be happening? When I look
at the watch the data is in the dataset.
Normally it does so this is hard to say, be aware this can only after that
you completed the entering of the data including the enter, in fact an
endedit.

Cor
Jun 27 '08 #4

"Cor Ligthert[MVP]" <no************ @planet.nlwrote in message
news:AD******** *************** ***********@mic rosoft.com...
John,
>So I have a few questions
1) Is this the correct/best way to be passing datasets to other forms?
How do other people do it? I have seen people passing binding sources?

I seldom use by ref in fact I think never. It is only needed as you create
a new object in a child class.
In this case clearly not, be aware that passing reference types is always
by the value of its reference.
Therefore passing by value is also cheaper (but not more than I thought an
integer) than by reference.

I did never did it, but there can be in my idea not be any harm to pass
the bindingsource and use that in your child form control, but remember
for these kind as things, forever pass by value. However then you can of
course not add directly in your underlying dataset, what you do in my
idea.

Be aware that you even can pass your datagridview on page one and by
casting, use the datasource of that and then again your bindingsource get
the underlying table. Something as (typed here not tested)

dim ds as DataSet =
DirectCast(Dire ctCast(myPassed DataGridView.Da taSource,Bindin gSource).DataSo urce,DataSet)
I do like the idea of passing in the datasource but I changed my mind on
that because we then don't get the advantage of using the visual tools.

I might give the gridview/casting thing a shot and see if I have any luck
with it.

As for the reason I wanted to do it; It is for a popup dialogform that
edits/displays the same information from the dataset in the main form. I
didnt want to have to manually copy things from the controls to the dataset
when the user clicks ok. I thought it'd be a fairly common thing people
would try and do.
>2) I am having problems with bindings, when I add a new row it doesnt
seem to create a record correctly (its not there when I look at the
watch, but the count increases). Is there something else I have to do to
make it rebind all the controls properly?

This is hard to answer as we don't know how you add a row, there are so
many methods for that.
>3) When the record already exists and I edit it the datagrid on the main
form doesnt update with any data. Why would this be happening? When I
look at the watch the data is in the dataset.
Normally it does so this is hard to say, be aware this can only after that
you completed the entering of the data including the enter, in fact an
endedit.

Cor

Hmm, I figured problem 2 and 3 were something to do with the binding not
being set up properly, I have tried endiniting. Yes it is hard to answer
cause there are many things that would just be too verbose to paste here. I
think im just gonna have to keep trying and experimenting and eventually I
will figure out what the hell is going wrong.

As for adding rows I just use bindingsource.a ddnew

One thing I am doing is that I have bindingsources on the visual part of the
designer as opposed to declaring them at runtime and bindinging them with
manual code. This doesnt work on its own so what I do in my constructor is
to set the bindingsource.d atasource to my referenced dataset and it
refreshes the bindings. (Im guessing this sounds confusing)..... my inkling
is that this is what is causing the problems.

Public Sub New(ByRef theDataset As myTypedDataset)
me.myBindingSou rce.datasource = theDataset
End Sub

Thanks Cor, I very appreciate your time and your thought out answer
Regards
John
Jun 27 '08 #5

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

Similar topics

3
14942
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) { document.images.src = eval("mt" +menu+ ".src") } alert("imgOff_hidemenu"); hideMenu=setTimeout('Hide(menu,num)',500);
4
4868
by: Ron Rohrssen | last post by:
I want to show a dialog and when the form (dialog) is closed, return to the calling form. The calling form should then be able to pass the child form to another object with the form as a parameter. For example, FormOptions formOptions = new FormOptions(); if (formOptions.ShowDialog(this) == DialogResult.OK) {
3
4756
by: Simon Harvey | last post by:
Hi, In my application I get lots of different sorts of information from databases. As such, a lot of information is stored in DataSets and DataTable objects. Up until now, I have been passing around chunks of data in DataTables/DataSets, simply because that was the format that they were in when the data was taken from the database. Now, I know this maybe a pretty silly question with a standard "it depends" answer, but I'm going to...
3
13589
by: JJ | last post by:
Hi, I need to pass a dataset to another win form along with a SqldataAdapter. I don't want to recreate the SqlDataAdapter again either. So to pass to another Win form in my windows form app, do I create the procedure to pass by ref? Which means I don't need to add ByRef because it is defaulted by ref, correct? And in the constructor of the win form that gets created. I need to add in parameters a DataSet and SqlDataAdapter correct? What...
25
5057
by: Stuart Hilditch | last post by:
Hi all, I am hoping that someone with some experience developing nTier apps can give me some advice here. I am writing an nTier web app that began with a Data Access Layer (DAL), Business Logic Layer (BLL) and User Interface Layer (UIL). The problem I found with this was circular referencing...
8
4414
by: Johnny | last post by:
I'm a rookie at C# and OO so please don't laugh! I have a form (fclsTaxCalculator) that contains a text box (tboxZipCode) containing a zip code. The user can enter a zip code in the text box and click a button to determine whether the zip code is unique. If the zip code is not unique, another form/dialog is displayed (fclsLookup) - lookup form/dialog. The zip code is passed to the lookup form/dialog by reference. I then load a...
19
2530
by: Jaime Stuardo | last post by:
Hi all.. I have created a business logic component that is used from my ASP.NET webform. It works, but connection string to the database is hard coded, as in this method : public DataSet GetCategories() { SqlConnection conn = new SqlConnection("Data Source=DEVSERVER;Initial Catalog=XXXX;User ID=X;Password=Y");
5
1186
by: Darious Snell | last post by:
I am using windows forms and vb.net. My problem is a little complex so please bear with me. I have written an application that references a .com based API linked to an external client application. The API exposes client user interface objects. One of the objects is similar to a grid. The first part of my application creates a reference to the grid object in the client application.
0
1544
by: Magnus Bergh | last post by:
I am developing an application for pocketpc and this involvs a but of juggling with different forms. I have an "order entry" type of application. On the main form I have a grid which displays Order headers. Let call this form "OrderList" From this view I edit/enter new orders by opening a new form for entering data. This is done using (more or less) the designer generated forms, so I have a "Order edit view dialog. I pass the binding...
0
8808
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
9316
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9179
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9077
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9023
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5959
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4729
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3160
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2525
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.