Firstly, I have this working in development, however when I publish to the production webserver, instead of generating the report, it asks me for login credentials again. Here is a snapshot of my entire code behind file: using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using CrystalDecisions.CrystalReports.Engine; using CrystalDecisions.Shared; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if ((ViewState["ParametersShown"] != null) && (ViewState["ParametersShown"].ToString() == "True")) { ReportListing myListing = new ReportListing(); BindReport(ConfigurationManager.AppSettings["reportlocation"].ToString() + myListing.GetReportFileName(Session["Report"].ToString())); } } protected void btnBuild_Click(object sender, EventArgs e) { CrystalReportViewer1.ParameterFieldInfo.Clear(); DateTime startDate = DateTime.Parse(Session["FromDate"].ToString()); DateTime endDate = DateTime.Parse(Session["ToDate"].ToString()); ParameterFields paramFields = new ParameterFields(); ParameterField crStartDate = new ParameterField(); ParameterField crEndDate = new ParameterField(); crStartDate.Name = "@StartDate"; crEndDate.Name = "@EndDate"; ParameterDiscreteValue dcrStartDate = new ParameterDiscreteValue(); ParameterDiscreteValue dcrEndDate = new ParameterDiscreteValue(); dcrStartDate.Value = startDate; dcrEndDate.Value = endDate; crStartDate.CurrentValues.Add(dcrStartDate); crEndDate.CurrentValues.Add(dcrEndDate); paramFields.Add(crStartDate); paramFields.Add(crEndDate); ReportListing myListing = new ReportListing(); BindReport(ConfigurationManager.AppSettings["reportlocation"].ToString() + myListing.GetReportFileName(Session["Report"].ToString())); CrystalReportViewer1.ParameterFieldInfo = paramFields; ViewState["ParametersShown"] = "True"; ViewState["ReportName"] = Session["Report"].ToString(); } private void BindReport(string FilePath) { ReportDocument Report = new ReportDocumen
jamesc69
Posts
-
Passing database login info to Crystal report - problem going to production -
Dynamically change Crystal Report Viewer sourceHi, I've written a number of Crystal reports, and I would like to get my report viewer to bind the report on change of dropdown. This does work, however for each one change it asks for the parameter information again. Below is my source - the parameters are the same across all reports and are held in session: protected void Page_Load(object sender, EventArgs e) { if ((ViewState["ParametersShown"] != null) && (ViewState["ParametersShown"].ToString() == "True")) { ReportListing myListing = new ReportListing(); BindReport("MYPATH" + myListing.GetReportFileName(Session["Report"].ToString())); } } protected void btnBuild_Click(object sender, EventArgs e) { DateTime startDate = DateTime.Parse(Session["FromDate"].ToString()); DateTime endDate = DateTime.Parse(Session["ToDate"].ToString()); ParameterFields paramFields = new ParameterFields(); ParameterField crStartDate = new ParameterField(); ParameterField crEndDate = new ParameterField(); crStartDate.Name = "@StartDate"; crEndDate.Name = "@EndDate"; ParameterDiscreteValue dcrStartDate = new ParameterDiscreteValue(); ParameterDiscreteValue dcrEndDate = new ParameterDiscreteValue(); dcrStartDate.Value = startDate; dcrEndDate.Value = endDate; crStartDate.CurrentValues.Add(dcrStartDate); crEndDate.CurrentValues.Add(dcrEndDate); paramFields.Add(crStartDate); paramFields.Add(crEndDate); CrystalReportViewer1.ParameterFieldInfo = paramFields; ReportListing myListing = new ReportListing(); BindReport("MYPATH" + myListing.GetReportFileName(Session["Report"].ToString())); ViewState["ParametersShown"] = "True"; } private void BindReport(string FilePath) { ReportDocument Report = new ReportDocument(); Report.Load(FilePath); SetTableLocation(Report.Database.Tables); CrystalReportViewer1.ReportSource = Report; } private void SetTableLocation(Tables tables) { ConnectionInfo connectionInfo = new ConnectionInfo(); connectionInfo.ServerName = ConfigurationManager.AppSettings["ReportDBServerName"].ToString(); connectionInfo.DatabaseName = ConfigurationManager.AppSettings["ReportDBDBName"].ToString(); connectionInfo.UserID = ConfigurationManager.AppSettings["ReportDBUserID"].ToString(); connection
-
Returning a parameter from a stored procHi, Thanks all, this is the correct solution Thanks James
-
Returning a parameter from a stored procHi, I have a stored proc that at the end executes the following line: Select @ID In my C# I have the following to try and grab it: SqlParameter AgentID = new SqlParameter("@ID", SqlDbType.Int, 4); AgentID.Direction = ParameterDirection.ReturnValue; sqlCmd.Parameters.Add(AgentID); int NewAgentID = 0; try { sqlCon.Open(); sqlCmd.ExecuteScalar(); sqlCon.Close(); NewAgentID = int.Parse(sqlCmd.Parameters["@ID"].Value.ToString()); return NewAgentID; } In debug this seems to set NewAgentID to -1, however it should be a legitimately returned variable from the stored proc, any ideas what is wrong?
-
Looping through XMLNodeList problemHi, First of all thanks all for your help, but this apparently isn't a coding problem, but actually a problem with my Vis Studio. My Vis Studio was not building a new dll each time and therefore any change I was making was having no effect. I created a new solution, added all the existing files into the new solution, and guess what - it now works! Apologies for wasting everyone's time.
-
Looping through XMLNodeList problemHere is a complete XML snapshot: <?xml version="1.0" encoding="utf-8">; <HotelAvail xmlns="http://www.transhotel.com/transHotel/2004A" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.transhotel.com/transHotel/2004A HotelAvailRQ.xsd"> <WholesalerID>TRANSHOTEL</WholesalerID> <Hotels> <HotelCode>1154718</HotelCode> </Hotels> <Dates> <CheckIn>2010-01-21</CheckIn> <CheckOut>2010-01-22</CheckOut> </Dates> <Rooms> <Room> <RoomRQId>1</RoomRQId> <Quantity>1</Quantity> <NumAdults>3</NumAdults> </Room> <Room> <RoomRQId>2</RoomRQId> <Quantity>1</Quantity> <NumAdults>2</NumAdults> </Room> </Rooms> </HotelAvail> If I run in debug mode, on the first pass through ForEach it says that the innertext will be 113 (for the whole occurrence of that node), on the second pass it says that the innertext will be 212 (which is correct). So the problem has got to be how the variables are set from the referenced nodes. For some reason it is selecting the 1st occurence of each element within Room even though it is running within a loop. I know this can be a problem with say SelectSingleNode, but I'm not using that. So therefore objRNode["RoomRQId"].InnerText is not iterative, and is always picking the 1st occurence with the document. A namespace is used and referenced as follows: XmlNamespaceManager ns = new XmlNamespaceManager(xmlDoc.NameTable); ns.AddNamespace("test", "http://www.transhotel.com/transHotel/2004A"); There is only one "Rooms" node, so that is selected explicitly so as to ensure no confusion. Objwriter is an XMLTextWriter which is merely writing the output.
-
Looping through XMLNodeList problemThe entire project is huge and references several classes, so it's impossible to include the whole code, below is a more concise example of what is occuring. Basically for every occurence of the "Room" node, I populate a datatable with the variables, and then write an output. It loops through my for each loop twice, but sets the variables each time to the first occurence only. And therefore I get two nodes output, which are both derived from the first datatable created, and the first set of room child nodes in the xml document. The rest of this project is working 100% perfectly, but this is the only area where I need to loop through a list of nodes, as all other nodes occur once. XmlNodeList nodeRooms = xmlDoc.SelectNodes("/test:HotelAvail/test:Rooms/test:Room", ns); foreach (XmlNode objRNode in nodeRooms) { intRoomRQId = int.Parse(objRNode["RoomRQId"].InnerText); strQuantity = objRNode["Quantity"].InnerText; intNumAdults = int.Parse(objRNode["NumAdults"].InnerText); DataTable dt = objAvailability.SelectHotelAvail(intRoomRQId, strQuantity, intNumAdults); if (dt.Rows.Count >0) { objWriter.WriteStartElement("Room"); objWriter.WriteStartElement("RoomRQId"); objWriter.WriteString(intRoomRQId.ToString()); objWriter.WriteEndElement(); //RoomRQID ..... other items from datatable are written here } }
-
Looping through XMLNodeList problemHi, this is merely a snippet. The variables are used within the loop, (but I didn't include all that). In debug, each variable is set to the first node value, and then when it loops through again, it sets it again to the first node value. Therefore it is looping the correct number of times, the problem seems to be in identifying the xpath to then set the variable to each occurence.
-
Looping through XMLNodeList problemHi, I have XML in the following structure: <Rooms> <Room> <RoomRQId>1</RoomRQId> <Quantity>1</Quantity> <NumAdults>3</NumAdults> </Room> <Room> <RoomRQId>2</RoomRQId> <Quantity>1</Quantity> <NumAdults>2</NumAdults> </Room> </Rooms> And each time, I get the values assigned as the first occurence of room. Running in debug mode, I can see the second node called within the For each loop, but the values are still assigned as the second occurence. Code below: XmlNodeList nodeRooms = xmlDoc.SelectNodes("/test:HotelAvail/test:Rooms/test:Room", ns); foreach (XmlNode objRNode in nodeRooms) { intRoomRQId = int.Parse(objRNode["RoomRQId"].InnerText); strQuantity = objRNode["Quantity"].InnerText; intNumAdults = int.Parse(objRNode["NumAdults"].InnerText); } So IntRoomRQID is set as 1 twice, when it should create a node of 1, and then a node of value 2.