CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2005
    Posts
    21

    C# Accessing dataset from multiple Winforms

    I have a program where am trying to access a dataset in the main form from a 2nd Winfrom. I have created a form 1 ref but when I use this to access the datatable in the dataset it doesnt seem to work. The following code is for Form 2 and I Movset1 is the dataset in the main form. I then try to use a dataview to access the main dataset.

    Code:
    
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Data.SqlClient;
    using System.Data.Common;
    
    namespace MovieDiary
    {
        public partial class Form2 : Form
        {
    
    
            DataView Dv2 = new DataView();
            public Form2()
            {
                
                InitializeComponent();
                
            }
    
            public Form1 F1 = new Form1();
            
    
            public void Form2_Load(object sender, System.EventArgs e)
            {
               
            }
            
    
             
             
            
            
            
            private void label1_Click(object sender, EventArgs e)
            {
    
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                if (textBox1.Text == "")
                {
                    MessageBox.Show(" Please enter a title to be deleted ");
                    return;
                       
                    
                }
    
    
                Dv2 = new DataView(F1.Movset1.Tables[0]);
                F1.dataGrid1.DataSource = Dv2;
                Dv2.RowFilter = "Title ='" + textBox1.Text + "'";
               
                
               
                
               
            }
        }
    }
    Last edited by DataMiser; June 10th, 2012 at 05:31 AM. Reason: added code tags

  2. #2
    Join Date
    Dec 2008
    Location
    Step Into(F11)
    Posts
    465

    Talking Re: C# Accessing dataset from multiple Winforms

    Please write the code inside the code tags .it is much better .and more readable .
    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Data.SqlClient;
    using System.Data.Common;
    
    namespace MovieDiary
    {
    public partial class Form2 : Form
    {
    
    
    DataView Dv2 = new DataView();
    public Form2()
    {
    
    InitializeComponent();
    
    }
    
    public Form1 F1 = new Form1();
    
    
    public void Form2_Load(object sender, System.EventArgs e)
    {
    
    }
    
    
    
    
    
    
    
    private void label1_Click(object sender, EventArgs e)
    {
    
    }
    
    private void button1_Click(object sender, EventArgs e)
    {
    if (textBox1.Text == "")
    {
    MessageBox.Show(" Please enter a title to be deleted ");
    return;
    
    
    }
    
    
    Dv2 = new DataView(F1.Movset1.Tables[0]);
    F1.dataGrid1.DataSource = Dv2;
    Dv2.RowFilter = "Title ='" + textBox1.Text + "'";
    
    
    
    
    
    }
    }
    }

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

Featured