以其他形式将数据从datagridview发送到datagrid

以其他形式将数据从datagridview发送到datagrid

本文介绍了以其他形式将数据从datagridview发送到datagridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我怎样才能将数据从Form2中的datagrid转换为c#中其他形式的datagrid?

How can i get data from datagrid in form2 to datagrid in other form in c#?

推荐答案


private void button1_Click(object sender, EventArgs e)
       {
           FormDestination formDest = new FormDestination();  //FromDestination is my seconcd form

           DataTable tableemp = new DataTable();

           using (SqlConnection con = new SqlConnection("user id=sa;password=just4fun;database=sdp;data source=SITT244"))  //Thease are your sql server credentials
           {
               using (SqlCommand cmd = new SqlCommand("select * from emp",con))
               {
                   SqlDataAdapter da = new SqlDataAdapter(cmd);
                   da.Fill(tableemp);
               }
           }

           Control[] ctlgrid = formDest.Controls.Find("dataGridDest", true);  //Finding the dataGridDest in form name as FormDestination

           DataGridView grid =(DataGridView) ctlgrid[0];   //Converting the control array to grid control

           grid.DataSource = tableemp;
           formDest.Show(); //Callling the second form from first Form


       }



以相同的方式将数据以哪种形式从哪个表绑定到datagrid,将相同的表分配给FormDestination中的datagrid



From which table you bind data to datagrid in first form in the same way assign the same table to datagrid in FormDestination


这篇关于以其他形式将数据从datagridview发送到datagridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 21:34