构造datatable临时数据

        void getData()
        {

            //init sqlconnection
            #region
            //SqlConnectionStringBuilder connbuilder = new SqlConnectionStringBuilder();

            //connbuilder.DataSource = "(local)";

            //connbuilder.IntegratedSecurity = true;

            //connbuilder.InitialCatalog = "AdventureWorks";



            start to make sql query

            //SqlConnection conn = new SqlConnection(connbuilder.ConnectionString);

            //sda = new SqlDataAdapter("select ContactID,FirstName,LastName,EmailAddress from personcontact where ContactID<=100;", conn);

            //SqlCommandBuilder commbuilder = new SqlCommandBuilder(sda);

            //sda.UpdateCommand = commbuilder.GetUpdateCommand();

            //dt = new DataTable();

            //sda.AcceptChangesDuringUpdate = true;

            //sda.Fill(dt);
            #endregion
            DataTable dt = GetTempData();
            listView1.ItemsSource = dt.DefaultView;
        }

        private DataTable GetTempData()
        {
            DataTable dt = new DataTable();
            DataColumn dc1 = new DataColumn();
            dc1.ColumnName = "ContactID";
            dc1.DataType = typeof(string);
            DataColumn dc2 = new DataColumn();
            dc2.ColumnName = "FirstName";
            dc2.DataType = typeof(string);
            DataColumn dc3 = new DataColumn();
            dc3.ColumnName = "LastName";
            dc3.DataType = typeof(string);
            DataColumn dc4 = new DataColumn();
            dc4.ColumnName = "EmailAddress";
            dc4.DataType = typeof(string);

            dt.Columns.Add(dc1);
            dt.Columns.Add(dc2);
            dt.Columns.Add(dc3);
            dt.Columns.Add(dc4);

            DataRow dr1 = dt.NewRow();
            dr1[0] = "1";
            dr1[1] = "Philippines";
            dr1[2] = "111";
            dr1[3] = "111";
            DataRow dr2 = dt.NewRow();
            dr2[0] = "2";
            dr2[1] = "Singapore";
            dr2[2] = "222";
            dr1[3] = "111";
            DataRow dr3 = dt.NewRow();
            dr3[0] = "3";
            dr3[1] = "Philippines";
            dr3[2] = "333";
            dr1[3] = "111";
            DataRow dr4 = dt.NewRow();
            dr4[0] = "4";
            dr4[1] = "Singapore";
            dr4[2] = "444";
            dr1[3] = "111";
            dt.Rows.Add(dr1);
            dt.Rows.Add(dr2);  
            dt.Rows.Add(dr3);
            dt.Rows.Add(dr4);  
            return dt;
        }D

转载于:https://www.cnblogs.com/panjiayuan/p/5628892.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值