码迷,mamicode.com
首页 > 其他好文 > 详细

项目知识点总结

时间:2014-06-20 23:02:19      阅读:245      评论:0      收藏:0      [点我收藏+]

标签:style   class   blog   code   tar   ext   

1、将对象modelList转换为DataTable表

private DataTable ListToDataTable(List<Tellyes.Model.QuestionOption> QuestionOptionList)
        {
            DataTable dt = new DataTable();

            if (QuestionOptionList.Count > 0)
            {
                PropertyInfo[] propertys = QuestionOptionList[0].GetType().GetProperties();
                foreach (PropertyInfo pi in propertys)
                {
                    System.Type colType = pi.PropertyType;
                    if ((colType.IsGenericType) && (colType.GetGenericTypeDefinition() == typeof(Nullable<>)))//出现可能为空的情况
                    {
                        colType = pi.PropertyType.GetGenericArguments()[0];

                    }
                    dt.Columns.Add(pi.Name, colType);
                }

                for (int i = 0; i < QuestionOptionList.Count; i++)
                {
                    ArrayList al = new ArrayList();
                    foreach (PropertyInfo pi in propertys)
                    {
                        object obj = pi.GetValue(QuestionOptionList[i], null);
                        al.Add(obj);
                    }

                    object[] array = al.ToArray();
                    dt.LoadDataRow(array, true);
                }
            }
            return dt;
        }

 

2、查询excel表格添加到dataset

public DataSet ExecleDs(string filenameurl)
        {
            string strConn = "Provider=Microsoft.ACE.OleDb.12.0;" + "data source=" + filenameurl + ";Extended Properties=‘Excel 12.0; HDR=YES; IMEX=1‘";
            OleDbConnection conn = new OleDbConnection(strConn);
            conn.Open();
            DataSet ds = new DataSet();
            string strSql = string.Format("SELECT * FROM [{0}$]", "Sheet1");
            OleDbDataAdapter odda = new OleDbDataAdapter(strSql, conn);
            odda.Fill(ds, "hou");
            return ds;
        }

 

3、将一文件上传到服务器中:所有操作都在后台

string clientIP = "192.168.4.22";
                string serverIP = "192.168.4.22";
                string clientFilesName = "shangchuan";
                string serverFilesName = @"QuestionUploadFile\" + userName;

                string fileName = "111.flv";
                string clientPath = @"\\" + clientIP + "\\" + clientFilesName + "\\" + fileName;
                string serverPath = @"\\" + serverIP + "\\" + serverFilesName + "\\" + fileName;

                System.IO.File.Copy(clientPath, serverPath,true );

前提是:将文件shangchuan,QuestionUploadFile设置共享属性,同时在安全属性上是目标机器增加应有权限。

 

4、DataTable排序处理

实例:

DataTable dt = new DataTable();
            dt.Columns.Add(new DataColumn("id", typeof(int)));
            dt.Columns.Add(new DataColumn("name", typeof(string )));
            dt.Columns.Add(new DataColumn("age", typeof(int)));

            for (int i = 0; i < 5; i++)
            {
                DataRow dr = dt.NewRow();
                dr["id"] = i;
                dr["name"] = i + "jim";
                dr["age"] = 10 - i;
                dt.Rows.Add(dr);
            }

            DataView dv = dt.DefaultView;
            dv.Sort = "age Asc";
            DataTable dt2 = dv.ToTable();

 

项目知识点总结,布布扣,bubuko.com

项目知识点总结

标签:style   class   blog   code   tar   ext   

原文地址:http://www.cnblogs.com/ysyn/p/3766039.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!