Click here to Skip to main content
15,892,072 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
(there are 2 forms..one form contains label and button and another form contain datagridview...i want that when i am clicking on button of 1st form it should redirect to 2nd form along with the label value and perform the operation on datagridview of 2nd form by the label value using sql command)
Form1
C#
private void button1_Click(object sender, EventArgs e)
       {
           ministatement mns = new ministatement();
           mns.Show();
           mns.label2.Text = label2.Text;
           mns.label4.Text = label4.Text;
       }

Form2
C#
public partial class ministatement : Form
   {
        SqlConnection connect = new SqlConnection(@"data source=ABHINAV-PC\ABHI;integrated security=true;initial catalog=ATM;");

       public ministatement()
       {
           InitializeComponent();
       }

       private void ministatement_Load(object sender, EventArgs e)
       {
            connect.Open();
SqlCommand cmd = new SqlCommand("select * from transactions where account_no='" + label4.Text.Trim().ToString() +"'" , connect);
DataTable dth = new DataTable();
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                da.Fill(dth);
                dataGridView1.DataSource = dth;
}
}
}
Posted

1 solution

Please don't do it like that!
See here: Transferring information between two forms, Part 1: Parent to Child[^]

You then do the operation in the property setter, and set the DataGridView from there.
 
Share this answer
 
Comments
Abhinav Chaudhary 13-Mar-14 12:55pm    
not understood...
OriginalGriff 13-Mar-14 15:00pm    
I didn't think it was complicated: what part is giving you problems?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900