我有一个名为reportviewer1.a报告的报告查看器,名为report.rldc。我使用以下代码获取数据并进入数据表。现在我想在报表查看器中显示数据表的数据。 代码如下所述。请帮忙:(
SqlDataAdapter dataadapter = new SqlDataAdapter(command);
DataTable table = new DataTable();
table.TableName = "Report showing result for " +
ComboBoxCategory.SelectedItem.ToString()+" +
ComboBoxQueryChoice.SelectedItem.ToString() +" from " +
dateTimePickerStarting.Value.ToString()+" to "+dateTimePickerEnding.Value.ToString();
table.Clear();
dataadapter.Fill(table);
命令文本是
SELECT Distinct Sale.Product_ID , S_Article ,
S_Size , SUM(S_Quantity) AS QuantitySold,SUM(Profit) AS Profit
FROM Product,Sale
WHERE Product.Product_ID=Sale.Product_ID
and(S_Date between (@Startdate)
and (@Enddate))" + SelectedCateogry +
" Group By Sale.Product_ID,(S_Article),(S_Size)
Order BY Profit DESC"
答案 0 :(得分:0)
var ConnString = System.ConfigurationManager.ConnectionStrings["dbconn"].ConnectionString;
SqlDataAdapter dataadapter;
DataTable someDataTable = new DataTable("ReportViewResults);
using (SqlConnection connStr = new SqlConnection(ConnString))
{
using (SqlCommand cmd = new SqlCommand("yourStoredProc or Sql Query", connStr))
{
cmd.CommandType = CommandType.StoredProcedure;//change to Text if your passing sql string
dataadapter= new SqlDataAdapter(cmd);
new SqlDataAdapter(cmd).Fill(someDataTable);
}
}