这个问题前面已经有解答了
提供一些基本的步骤,关于更详细的信息,请参考下面的链接:
1.Solution Explorer/Add/Add New Item…/DataSet,按照提示建立DataSet;
2.Solution Explorer/Add/Add New Item…/Crystal Report,在建立数据库链接时(Database Expert窗口),请选择<Project Data>,利用上一步建立的DataSet。
如下提供一段示例代码供您参考(用来建立数据库链接,填充DataSet,并绑定到报表文件中):
private void BindReport()
{
SqlConnection myConnection = new SqlConnection();
myConnection.ConnectionString = "Server=localhost;database=pubs;uid=sa;pwd=sa"; SqlCommand myCommand = new SqlCommand();
myCommand.Connection = myConnection;
//在这里根据您的情况,动态指定设定SQL语句
myCommand.CommandText = "Select * from Stores";
myCommand.CommandType = CommandType.Text; SqlDataAdapter myDA = new SqlDataAdapter();
myDA.SelectCommand = myCommand;
//这里的Dataset1为上面创建报表时建立
Dataset1 myDS = new Dataset1();
myDA.Fill(myDS, "Stores");
CrystalReport1  oRpt = new CrystalReport1();
oRpt.SetDataSource(myDS);
CrystalReportViewer1.ReportSource = oRpt;
}
请根据您系统的实际情况,将提供的代码进行修改。