4 Replies - 1527 Views - Last Post: 12 December 2013 - 02:43 PM Rate Topic: -----

#1 d.p.l.t   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 02-January 13

display mysql result in another form datagridview

Posted 11 December 2013 - 10:31 PM

i have been doing some reading and research and have not found anything too solid ... so here it goes...

i am creating an inventory system which is centered around a central data grid display.

the criteria for the search of the database is done on another form...

what i want is for the result from the "search" form to be displayed in that central data grid on the "main" form.

i have seen examples in many forums of passing text value from form to form , i have tried modifying and adapting but nttn.

any insight would be greatly appreciated

Is This A Good Question/Topic? 0
  • +

Replies To: display mysql result in another form datagridview

#2 _HAWK_   User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1162
  • View blog
  • Posts: 4,444
  • Joined: 02-July 08

Re: display mysql result in another form datagridview

Posted 11 December 2013 - 10:41 PM

Great time to add the Data Access Layer. This would allow you to keep the Database requests in one place. Here you can have many methods that returns your data - including a filtered query.

This post has been edited by _HAWK_: 11 December 2013 - 10:41 PM

Was This Post Helpful? 0
  • +
  • -

#3 thecoat   User is offline

  • D.I.C Addict

Reputation: 153
  • View blog
  • Posts: 537
  • Joined: 07-December 13

Re: display mysql result in another form datagridview

Posted 11 December 2013 - 11:45 PM

A form is nothing more than a class so you can add properties and methods to it and call them from another class after getting a handle on the form.

Public Class Form1

    Private _storedItemID As Integer
    Public WriteOnly Property ItemID As Integer
        'Removing WriteOnly in the prior line and uncommenting the following would allow us to read the property from another class or module
        'Get
        '    Return _storedItemID
        'End Get
        Set(value As Integer)
            _storedItemID = value
            RequeryDataSource(value)
        End Set
    End Property


    Private Sub RequeryDataSource(ByVal itemID As Integer)
        'Here you invoke your query of the recordsource passing in itemID as the filter
'And if you've implemented a DAL as Hawk suggested you can pass a reference to the DAL around between forms as well especially if you implement transactions inside your DAL.
    End Sub


    'Optionally we could call a method from another form:
    Public Sub DisplayRecord(ByVal itemID As Integer)
        RequeryDataSource(itemID)
    End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub
End Class


How you get a handle on the other form depends a bit on your application design.

This post has been edited by thecoat: 11 December 2013 - 11:48 PM

Was This Post Helpful? 0
  • +
  • -

#4 _HAWK_   User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1162
  • View blog
  • Posts: 4,444
  • Joined: 02-July 08

Re: display mysql result in another form datagridview

Posted 12 December 2013 - 08:32 AM

@thecoat, while technically your right, it is not a good design choice. Why ask another form to get it's data? What if that form is not open and available to do it? If the DAL is in place any form can query data - so simple.
Was This Post Helpful? 0
  • +
  • -

#5 thecoat   User is offline

  • D.I.C Addict

Reputation: 153
  • View blog
  • Posts: 537
  • Joined: 07-December 13

Re: display mysql result in another form datagridview

Posted 12 December 2013 - 02:43 PM

_HAWK_ my impression was that the parameters for a search would be passed between forms, and that the form displaying the data would be the one to actually query the data (preferably through a DAL), but that it would get the parameters for the query from another form.

I did make a huge assumption, and that was the whole reason for the "search" form was to keep the "main" form uncluttered to maximize the display of data, and that the instance of the search form would be created and controlled by the main form. If the main form was then closed the search form would close with it, so you wouldn't have to worry about the search form trying to call properties or methods of a non existent main form.

Attached is a quick sample project I did showing what I thought the OP was doing, except it just updates a textbox on the main form with text entered on a search form.

Attached File(s)


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1