//如下是将DB的数据放到DataTable
public DataTable SelSQL(String SQL)
{
DataTable Table = new DataTable();
SqlConnection myCon = new SqlConnection(LinkStr); //Linestr为连接路径
SqlCommand myCom = new SqlCommand(SQL, myCon);
myCom.CommandTimeout = 0;
SqlDataAdapter Adapter = new SqlDataAdapter(myCom);
try
{
Adapter.Fill(Table);
return Table;
}
catch (SqlException e)
{
MessageBox.Show(e.Message);
return Table;
}
finally
{
myCom.Dispose();
}
}
//在调用的时候再定义一个DataTable
//最后再将数据一笔笔指派个excel栏位即可