如何对其他表单传递的值执行操作 [英] how to perform operations on values of passed by other forms

查看:85
本文介绍了如何对其他表单传递的值执行操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(有2个表单..一个表单包含标签和按钮,另一个表单包含datagridview ...我希望当我点击第一个表单的按钮时,它应该重定向到第二个表单以及标签值并执行使用sql命令通过标签值对第二种形式的datagridview进行操作)

Form1

(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

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


Form2

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;
}
}
}

推荐答案

请不要那样做!

请参阅:在两个表单之间传输信息,第1部分:父母与孩子 [ ^ ]



然后在属性设置器中执行操作,并从那里设置DataGridView。
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.


这篇关于如何对其他表单传递的值执行操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆