如何在运行时更改Crystal Report的ODBC数据库连接
1个回答
展开全部
C#使用Crystal Report制作报表您态指定数据源及更新报表内容
您通DataSet式访问台数据库您需要手编码提取数据填充DataSet并传递报表文件您态指定报表数据源面提供些基本步骤关于更详细信息请参考面链接:
1.Solution Explorer/Add/Add New Item…/DataSet按照提示建立DataSet;
2.Solution Explorer/Add/Add New Item…/Crystal Report建立数据库链接(Database Expert窗口)请选择利用步建立DataSet
提供段示例代码供您参考(用建立数据库链接填充DataSet并绑定报表文件):
Private Sub 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;
End Sub
您通DataSet式访问台数据库您需要手编码提取数据填充DataSet并传递报表文件您态指定报表数据源面提供些基本步骤关于更详细信息请参考面链接:
1.Solution Explorer/Add/Add New Item…/DataSet按照提示建立DataSet;
2.Solution Explorer/Add/Add New Item…/Crystal Report建立数据库链接(Database Expert窗口)请选择利用步建立DataSet
提供段示例代码供您参考(用建立数据库链接填充DataSet并绑定报表文件):
Private Sub 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;
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询