来自web.config-Crystal Reports的Connectionstring

时间:2011-01-25 12:53:31

标签: asp.net sql-server asp.net-mvc crystal-reports connection-string

我有以下功能来创建水晶报告。我想更改我的功能,以便它使用web.config

中的连接信息
MyRepository _MyRepository = new MyRepository();            
System.Data.SqlClient.SqlConnection myConnection = new System.Data.SqlClient.SqlConnection();
myConnection.ConnectionString = "Data Source=MySRV;Initial Catalog=mydb;Persist Security Info=True;User ID=sa;Password=mypass";
System.Data.SqlClient.SqlCommand MyCommand = new System.Data.SqlClient.SqlCommand("dbo.spMySP");
MyCommand.Connection = myConnection;
MyCommand.Parameters.Add("@PositionID", SqlDbType.Int).Value = (cmbPositions.SelectedValue == "" ? 0 : Convert.ToInt32(cmbPositions.SelectedValue));
MyCommand.CommandType = System.Data.CommandType.StoredProcedure;
System.Data.SqlClient.SqlDataAdapter MyDA = new System.Data.SqlClient.SqlDataAdapter();
MyDA.SelectCommand = MyCommand;
ASale _DS = new ASale();
MyDA.Fill(_DS, "dbo.spMySP");
rptSale oRpt = new rptSale();
oRpt.SetDatabaseLogon("sa", "mypass");
oRpt.SetDataSource(_DS);
oRpt.SetParameterValue(0, "param1");
oRpt.SetParameterValue(1, "param2");
oRpt.SetParameterValue(2, "param3" );
oRpt.SetParameterValue(3, (cmbPositions.SelectedValue == "" ? 0 : Convert.ToInt32(cmbPositions.SelectedValue)));
CrystalReportViewer1.ReportSource = oRpt;

由于

1 个答案:

答案 0 :(得分:0)

myConnection.ConnectionString = ConfigurationManager
    .ConnectionStrings["ConStrName"]
    .ConnectionString;