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;
        }

posted @ 2011-10-20 16:18  风一样的大叔  阅读(500)  评论(0编辑  收藏  举报