|
-
Feb 18th, 2004, 09:34 AM
#1
Thread Starter
New Member
ADO.NET and binding data on new form
Hi, I am trying to start a project off and I am finding it difficult to decide on the way to go, can I ask your help?
In simple terms, I have a main form with a dataAdapter, Connection and a dataset. On that form I have a grid bound to the dataset. That grid is "filled" with the dataset.
I would like the user to select the row they would like to edit and for an edit button to open an "Editing" form. I need this form to display the data from the selected record and allow the user to edit the fields and then select "save changes" or "discard". I would like the changes then to be applied to the dataset on the original form (and in turn the grid) as the edit form closes. I can then do a dataset.update I believe?
I am having many problems with databinding the textboxes on the new edit form to the original dataset. I am VERY confused with databindings, currencymanagers etc. etc.
Is there any kind person out there that can show me an example of this functionality in an example project? If not, does anyone know of a tutorial that goes into new forms and databinding to existing datasets? I have tried numerous methods only to fail dismally.
In the past (VB6) I would have passed the grid values to the new form textboxes. Then, when the user clicked Save, I would have updarted the source database and refreshed the grid on the original form. But after reading for what seems for ever about ADO.NET and its benefits I thought I should use it!
Many thanks
Darren
(moderators: should this be in the Database forum??)
-
Feb 19th, 2004, 10:47 AM
#2
New Member
Edit, Update and Cancel with a Dataset and Grid
If you can get a copy of "The Ultimate VB.Net and ASP.Net Code Book" by Karl Moore, there is an excellent step by step treatment of exactly what you need on pages 158 - 166.
Since it is lengthy and detailed, it is more beneficial to understand all that is presented rather than just see the code that implements it. The presentation covers setting up the connection, dataadapter, datagrid, buttons for edit, update and cancel (in a template column within the datagrid) and all the code for Page Load, ItemDataBound, EditCommand, UpdateCommand and CancelCommand. The code for UpdateCommand includes refilling the original grid with the upadted dataset values.
I can tell you that this book has proven invaluable to me. It covers numerous, everyday, practical solutions that I have used for various implementations. They all work well and have saved countless hours of research, testing and debugging.
Good Luck.
-
Feb 19th, 2004, 11:54 AM
#3
Thread Starter
New Member
Thanks for your reply Steve, much appreciated. I will add the book to my list of reading material! I have 3 Vb.NET books already and I have read them all. I feel extremely dense here but I am having problems with what used to be the most simple tasks.
To temporarilly get around these dataset issues, I have tried to call functions on the mainform from a newly opened form. I cant even access those functions from my new form! Boy, I am in need of help. 
If anyone has a simple project that shows a real simple example of one form calling a function from another I would be very grateful
Soop
-
Feb 19th, 2004, 11:58 AM
#4
Sleep mode
What version of VB.NET have you got so I can give you a sample ?
-
Feb 19th, 2004, 12:19 PM
#5
Sleep mode
Never mind , I already posted an example in this link : http://www.vbforums.com/showthread.p...highlight=call . It's VB.NET 2003 . If you don't have it , then get the converter under my signature to get it backward compatible with VB.NET 2002 . If you still need help , then post here .
-
Feb 20th, 2004, 10:16 AM
#6
Thread Starter
New Member
Thanks very much Pirate.
That helped me very much. I am just about grasping the different way that .NET handles form instancing.
I do have another Q tho. What if I want to set the properties of the original(form1) form from the new form (form2)??
Many thanks, your example code was very handy.
-
Feb 20th, 2004, 11:48 AM
#7
Sleep mode
Exactly the same way . The idea is to get reference of the form you want to change . Since Forms in .NET are classes and classes are passed byref we'll do it this way , through the constructor :
Steps :
in Form2 do this :
Override the constructor to take reference of Form1 :
VB Code:
Dim frm2 As Form
Public Sub New(ByVal frm1 As Form)
InitializeComponent()
Me.frm2 = frm1
End Sub
Then ,
in a button on Form 2 , paste this code :
VB Code:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles Button2.Click
Me.frm2.Text = "Changed from Form2"
End Sub
Third , Go to Form1 and change the code to this :
VB Code:
Dim f2 As New Form2(Me)
f2.Show()
Run , test , Working ....
If you got stuck just shout and we'll be around .
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|