DataSource

I have an App which will use several diferent forms within the app. All will be accessing the same database and associated Tables. Do I need to add a new DataSet/Source for each form

Thanks,

Jeff



Answer this question

DataSource

  • Pavana

    hi,

    yes , if your form do something important , if your form just edit one record or so you can user properties to pass data between forms, even you can pass dataset between forms through properties you can review absolute beginner video's about creating channel form

    hope this helps



  • perfect13

    As an example I have MyDataBase.mdf and three forms, Form1, Form2 and Form3. I will then have three datasets i.e. MyDataBaseDatSet1, MyDataBaseDatSet2, MyDataBaseDatSet3 and then each table will will have a TableAdapter1,2 and 3 etc.
  • shade

    Another way using OO

    '\\ Within Form 1

    '\\ I have called Form 3 constuctor passing in the personTable object as follows

    Dim objpersonTable As New Form3(PersonTable)

     

    '\\ Within Form3

    Public Class Form3

    Private m_personTable As Object '\\ private variable to hold personTable object

    Public Sub New(ByVal personTable As Object) '\\ Constructor

    InitializeComponent()

    m_personTable = personTable

    End Sub

     

    Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    With DataGridView1

    .DataSource = m_personTable

    End With

    End Sub

    End Class


  • JoLu

    hi,

    yes

    you add dataset to your solution just once , and it will appear in your solution explorer. to use it you have to add instances to your forms

    best regards



  • phfjeld

    Hi,

    You could do this:

    I have the following in form1 for example:

    '\\ By adding the the following line at the Form1 Declaration level and declaring it as Public you make it available to all code within the application(defining its scope) This then allows me to use the same PersonTable within form2

    '\\ With Form1.. This method will fill a datagridview control on form1

    Public PersonTable As New Database1DataSet.dataDataTable

    '\\ The following code creates an instance of the datasets tableAdapter

    '\\ I then fill the PersonTable with records from the database

    Private Sub loadGrid1(ByVal extension As String)

    Dim PersonDataAdapter As New Database1DataSetTableAdapters.dataTableAdapter

    PersonDataAdapter.FillBy(PersonTable, extension) '\\ fill persontable with records that match value of variable extension

    '\\ The .FillBy method was configured using the sql wizard to return all records who's last name = extension

    With DataGridView1

    .DataSource = PersonTable '\\ sets datasource for Datagrid1 to PersonTable

    End With

    End Sub

    '\\ The following within Form2

    '\\I am using the same table to fill another datagridview control on this form Form2

    Private Sub Form2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    With Me.DataGridView1

    .DataSource = Form1.PersonTable

    End With

    End Sub

    Ron


  • DataSource