Question : Crystal in Visual Studio dynamic Database persistant on postback

I wanted to dynamically link my Crystal to the connection string in the Web config, I found code to do this. It works as long as I don't need to move off of page one. But moving off page one, (if dynamic logic is in (!IsPostBack) causes either the dynamic link to be lost and I get page 1 displayed empty.  Or moving off page one, (if dynamic logics is not in (!Ispostback) causes the logic to be reinitalized and I still find myself on page one, no matter what I do.. page next, page last, Enter a page # ..

so something, has to be to reset the connection.. But not all the logic,  so it doesn't keep resetting to page one..

Does anyone know the special secret of what to set and what not to set on a postback???
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
using System.Data.SqlClient; // needed for database
using CrystalDecisions.CrystalReports.Engine; //needed for dynamic Crystal

   string reportName = string.Empty;
    static ConnectionStringSettings conSettings =     ConfigurationManager.ConnectionStrings["WannalancitConnectionString"];
 
   protected void Page_Prerender(object sender, EventArgs e)
    {
        reportName = (string)Cache["CrystalRptName"];

        if (!IsPostBack)
        {
            CrystalReportSource1.Report.FileName = reportName;
       }
            if (reportName.IndexOf("testuntrained.rpt") > -1)
            {
                setDynamicDB();
            }
             if (CrystalReportSource1.Report.FileName != reportName)
                 CrystalReportSource1.Report.FileName = reportName;
   }
    protected void btnBack_Click(object sender, EventArgs e)
    {
        Response.Redirect("f_MenuReports.aspx");

    }
    private void setDynamicDB()
    {
        try 
	{	
            string conStr = System.Configuration.ConfigurationManager.AppSettings["WannalancitConnectionString"];
            string strReportPath = Server.MapPath("~/Reports/testuntrained.rpt");
            //SqlConnection sqlConnection = new SqlConnection(conStr);
            string connectionInfo = conSettings.ConnectionString;
            SqlConnection sqlConnection = new SqlConnection(connectionInfo);

            SqlCommand Command = new SqlCommand();
            Command.Connection = sqlConnection;
            Command.CommandText = "UnTrainedReport";
            Command.CommandType = CommandType.StoredProcedure;

            SqlDataAdapter Adapter = new SqlDataAdapter(Command);

            dsUntrainedRpt ds = new dsUntrainedRpt();
            Adapter.Fill(ds,"UntrainedReport");
            ReportDocument cr = new ReportDocument();
            cr.Load(strReportPath);
            cr.SetDataSource(ds.Tables["UntrainedReport"]);
            CrystalReportViewer1.ReportSource = cr;
		
	}
	catch (Exception exp)
	{
		
		lblErrorMsg.Text = exp.Message;
	}
    }
}

Answer : Crystal in Visual Studio dynamic Database persistant on postback

and let the following in faults.js
1:
2:
3:
4:
function ShowPhoto(equipid) {
    var vara = "/EquipmentPhotos/pic" + equipid + ".jpg";
    document.getElementById('EquipPhoto').setAttribute('src', vara);
}
Random Solutions  
 
programming4us programming4us