将数据表绑定到数据网格 [英] Binding datatable to datagrid

查看:76
本文介绍了将数据表绑定到数据网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我写了一个返回DataTable的函数.并在按钮Click事件中调用了该函数,因此当引发该事件时,该函数将返回数据表,并且我能够将数据表绑定到数据网格.问题是当第二次引发按钮事件时,第二次引发按钮事件时,在数据网格中看不到第一次事件中绑定的数据,因此需要在数据网格中显示新旧信息,所有这些是COMPACT FRAMEWORK-> WINCE APPLICATION

此功能已定义

Hi everyone,
I wrote a function which returns DataTable. And called that function in button Click event so when the event is raised the function returns the data table and I am able to bind the data table to data grid. And the problem is when the button event is raised for the second time the data which is bound in the first event is not seen in datagrid when button event raised second time so need to display the old and new information in the data grid and all this is COMPACT FRAMEWORK->WINCE APPLICATION

THIS IS FUNCTION DEFINED

public DataTable getdetails(ComboBox descp, ComboBox veitype)
        {
            InitializeDB();
            SqlCeCommand scmd = new SqlCeCommand();
            DataTable dt = new DataTable();
            SqlCeDataReader sdr;            
            try
            {
                scmd = con.CreateCommand();

                scmd.CommandText = "SELECT CHALLAN_CODE,CHALLAN_DESC,AMOUNT" + " FROM MB_MST_CHALLAN WHERE CHALLAN_DESC='" + descp.Text + "'AND (VEHICLE_TYPE='" + veitype.Text + "' OR VEHICLE_TYPE='A') AND STATUS='A'";
                SqlCeDataAdapter da = new SqlCeDataAdapter(scmd);
                da.Fill(dt);               
            }      
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                scmd.Dispose();
                CloseDbConnection();
            }
            return dt;
        }

推荐答案

您需要将旧数据表合并为新数据表
you need to merge the old datatable to new datatable


我们可以合并2个数据表
如果可能的话,您可以通过一些代码来指导我吗?
Can we Merge 2 data tables
if possible Can u guide me thru some code


<pre lang="vb">Dim dt1 As New DataTable
       dt1.Columns.Add("name")

       dt1.Rows.Add("NAME1")

       Dim dt2 As New DataTable
       dt2.Columns.Add("name")

       dt2.Rows.Add("NAME2")

       dt2.Merge(dt1)




但请确保两个表都具有相同的列名




but make sure that both table having same column names


这篇关于将数据表绑定到数据网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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