C#中读取存储过程中临时表中的数据的写法
public DataTable GetOpticalInfo(string begindate, string enddate, string prefromid)
{
const string connStr = @"Data Source=127.0.0.1;DataBase=master;User ID=sa;PWD=123"
var conn = new SqlConnection(connStr);
var ds = new DataSet();
var dt = new DataTable();
var strsql = "select * from ##临时表";
strsql += " where 1=1";
if (begindate != null && enddate != null)
strsql += " and 入库时间 between '" + begindate + "' and '" + enddate + "'";
strsql += " order by id desc";
try
{
conn.Open();
var cmd = new SqlCommand(strsql, conn);
SqlDataAdapter adp = new SqlDataAdapter(cmd);
adp.Fill(ds, "table1");
}
catch (Exception ex)
{
throw ex;
}
finally
{
conn.Close();
}
dt = ds.Tables[0];
return dt;
}