• 构造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

  • 相关阅读:
    面向对象进阶
    初识面向对象
    模块和包
    day 17递归函数
    pip命令无法使用
    Python中的iteritems()和items()
    C# 截取字符串
    Python连接Mysql数据库
    【PYTHON】 Missing parentheses in call to 'print'
    javaScript中with函数用法实例分析
  • 原文地址:https://www.cnblogs.com/panjiayuan/p/5628892.html
Copyright © 2020-2023  润新知