C#动态创建DataTable
时间:2010-11-23 来源:aisoon99
public DataTable Gettmp_CallByArea(System.Collections.ArrayList provinceName)
{
DataTable dt = new DataTable();//手动创建的新数据表
//define the table’s schema
dt.Columns.Add(new DataColumn("proname", typeof(string)));
try
{
DataTable dt1 = null;//返回的DataTable
if (provinceName.Count > 0)
{
for (int i = 0; i < provinceName.Count;i++)
{
if (provinceName[i].ToString() != null)
{
dt1=GetData(provinceName[i].ToString(), dt);
}
else
{
dt1 = null;
}
}
}
}
catch
{
return null;
}
return dt1;
}
public DataTable GetData(string proname, DataTable dt)
{
DataRow dr = dt.NewRow();
dr["proname"] = proname;
dt.Rows.Add(dr);
return dt;
}