DataSet 动态添加列

 public DataSet GetNewId(List<string> IdArr)
        {
            DataSet ds = new DataSet();
            DataTable newtb = new DataTable();
            DataColumn column = new DataColumn("cnt", typeof(string));//新增列
            newtb.Columns.Add(column);

            for (int i = 0; i < IdArr.Count; i++)
            {
                StringBuilder sbSql = new StringBuilder();
                sbSql.Append("insert into y (PatientID,PathologyNumber,PatientState,Classification,HospitalOfDelivery,DepartmentOfDelivery,"+
                               " Remark8,CliMedicalID,MedicalClass,ImageCheck,ControlType from  y where id='" + IdArr[i] + "'; SELECT @@IDENTITY as id");


                 object o = DbHelperMySQL.GetSingle(sbSql.ToString());
                 if (o!=null)
                 {
                     DataRow newRow = newtb.NewRow();
                     newRow["cnt"] = o.ToString();
                     newtb.Rows.Add(newRow);
                 } 
            }
            ds.Tables.Add(newtb);
             
            return ds;
        }

 

posted @ 2017-04-27 14:44  幽冥狂_七  阅读(1348)  评论(0编辑  收藏  举报