Results 1 to 7 of 7

Thread: ADO.NET and binding data on new form

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2002
    Posts
    15

    Question 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??)

  2. #2
    New Member
    Join Date
    Feb 2004
    Location
    NY
    Posts
    3

    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.

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2002
    Posts
    15
    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

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    What version of VB.NET have you got so I can give you a sample ?

  5. #5
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    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 .

  6. #6

    Thread Starter
    New Member
    Join Date
    Sep 2002
    Posts
    15
    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.

  7. #7
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    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:
    1. Dim frm2 As Form
    2.  
    3. Public Sub New(ByVal frm1 As Form)
    4.         InitializeComponent()
    5.         Me.frm2 = frm1
    6. End Sub


    Then ,

    in a button on Form 2 , paste this code :

    VB Code:
    1. Private Sub Button2_Click(ByVal sender As System.Object, ByVal
    2. e As System.EventArgs) Handles Button2.Click
    3.         Me.frm2.Text = "Changed from Form2"
    4.  End Sub


    Third , Go to Form1 and change the code to this :

    VB Code:
    1. Dim f2 As New Form2(Me)
    2. 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
  •  



Click Here to Expand Forum to Full Width