示例代码:
using System.Data;
using System.Data.SqlClient;
public static DataSet GetSalesData(string connectionString, int year)
{
string query = "SELECT * FROM Sales WHERE Year = @Year";
using (SqlConnection connection = new SqlConnection(connectionString))
using (SqlCommand command = new SqlCommand(query, connection))
{
command.Parameters.AddWithValue("@Year", year);
SqlDataAdapter adapter = new SqlDataAdapter(command);
DataSet dataSet = new DataSet();
adapter.Fill(dataSet);
return dataSet;
}
}
AdventureWorks
exec GetSalesData @Year = @Year
=Parameters!Year.Value
在项目属性中的“报表”选项卡中添加不同环境的报表服务器地址、用户名和密码。
在 Visual Studio 的“解决方案资源管理器”中,