日期:2014-05-18  浏览次数:20386 次

ASP.net 建一个临时表
建立一个临时表,里面的字段和数据库的一张表的字段是一样的


  DataTable myda = new DataTable(); //实力一个新表
  DataColumn datacol = myda.Columns.Add("ID"); //给这个新表添加字段
  datacol.DataType = Type.GetType("System.String" ); //表示添加字段的类型
  datacol = myda.Columns.Add("G_number");
  datacol.DataType = Type.GetType("System.String");
  datacol = myda.Columns.Add("G_name");
  datacol.DataType = Type.GetType("System.String");
  datacol = myda.Columns.Add("G_price");
  datacol.DataType = Type.GetType("System.String");
  datacol = myda.Columns.Add("datetime");
  datacol.DataType = Type.GetType("System.String");
  datacol = myda.Columns.Add("note");
  datacol.DataType = Type.GetType("System.String");
  this.ViewState["table"] = myda;

我觉得这样添加字段比较麻烦,有没有简单点的,数据库的表表名为BS_Dept
有没有简单点建临时表的那种方法。。。。


------解决方案--------------------
datacol = AddColumn({"G_number","G_name","G_price","datetime","note"});
private void AddColumn(stirng cValue[])
{
 for(int i=0;i<cValue.lenges,i++)
{
 datacol.DataType = Type.GetType("System.String");
datacol = myda.Columns.Add(cValue[i]);
}
}
您看是不是简单些了