Wednesday, September 30, 2009

Unable to print in CrystalReport Viewer in ASP.Net

This is due to the web page consists of AJAX update panel issue. If the CrystalReport Viewer inside the update panel then the print button when click unable to print. To resolve put the CrystalReportViewer outside of the update Panel or else set trigger PostBack to the contentPlaceHolder for example.

Sunday, September 13, 2009

Crystal Report Viewer Errors in VIsual Studio 2005




Error Message : Sys.WebForms.PageRequestManagerParserErrorException

In my case i Have a Mainpage that links a page consist of Crystal Report Viewer. I link it using server.transfer

If you got this error above. This is due to link up to a page consist of Crystal Report Viewer using Server.Transfer. Try using Response.Redirect() with query string parameters or cross-page posting

Saturday, September 12, 2009

Crystal Report Viewer :The system cannot find the path specified.

Crystal Report Viewer :The system cannot find the path specified.

This is because your crystal Report source Control in VS2005 . Report FileName Path problem



Notice The Report report filename="XXX\PurchaseXXX.rpt" . It should be the correct way report filename="~\XXX\PurchaseXXX.rpt"

Try it and see it yourself.

Friday, September 4, 2009

Crystal Report Error Logon failed.Details:crdb_adoplus: Object Reference not set to an instance of an object

Error Description:

Logon failed. Details: crdb_adoplus : Object reference not set to an instance of an object. Error in File C:\DOCUME~1\XXX\LOCALS~1\Temp\XXXX {3309D862-8288-4B18-AEC2-FA3B78AA2BA3}.rpt

Solution:

Check the field explorer. Then select Database Expert. Make sure that the tables selected matches in the xxx.aspx file consists of properties Report datasource in CrystalReportSource control

Crystal Report Error in ASP.NET C# : The system cannot find the path specified.

The system cannot find the path specified.
System.Runtime.InteropServices.COMException: The system cannot find the path specified.

Solution :

Configure the Report source properly. Make sure the path of the file rpt is correct.

Crystal Report Viewer Error in ASP.Net 2005

 

Invalid index. (Exception from HRESULT: 0x8002000B (DISP_E_BADINDEX))

System.Runtime.InteropServices.COMException: Invalid index. (Exception from HRESULT: 0x8002000B (DISP_E_BADINDEX))

Solution

  1. Go To xxx.rpt and click at the fields eplorer.
  2. Select the Database fields.
  3. Right Click the table for Set Datasource Location.
  4. Match The Tables in Current Data Source and Replace With for Update. Click Close
  5. Verify Database.
  6. The Database is uptodate message will appear and hopefully no error after this.
     

Tuesday, August 25, 2009

Understanding DateTime and TimeSpan in .Net

 
Here are the example
//Creating Two Instance of DateTime
DateTime dt1 = new DateTime();
DateTime dt2 = new DateTime();
//Initializing DateTime Object
dt1 = DateTime.Now.Date; //Initializing with Current Date
Response.Write(dt1.ToString() + "<br>");
//Output: 22-06-2007 00:00:00
//Examples for DateTime Manipulation in .Net
//Example 1 : Adding Minutes to Current Date.
dt1 = dt1.AddMinutes(5.0);
Response.Write(dt1.ToString() + "<br>");
//Output: 22-06-2007 00:05:00
//Example 2 : Adding Seconds to DateTime Object., similarly you can add milliseconds
dt1 = dt1.AddSeconds(30.0);
Response.Write(dt1.ToString() + "<br>");
//Output: 22-06-2007 00:05:30
//Example 3 : Adding Hours to DateTime Object in .Net.
dt1 = dt1.AddHours(5.0);
Response.Write(dt1.ToString() + "<br>");
//Output: 22-06-2007 05:05:30
//Example 4 : Adding Time to DateTime Object.
//You can replace Example 1,2 and 3 by simply adding TimeSpan with your desired
//TimeSpan value.
//Here we are adding 5 Hours, 5 Minutes and 30 Seconds.
dt1 = dt1.Add(new TimeSpan(5,5,30));
Response.Write(dt1.ToString() + "<br>");
//Output: 22-06-2007 10:11:00
//Example 5 : Adding Days to DateTime Object in .Net
dt2 = dt1.AddDays(7.0); //Initializing dt2 object with 7 days ahead from
//dt1 DateTime value.
Response.Write(dt2.ToString() + "<br>");
//Output: 29-06-2007 10:11:00
//Example 6 : Adding Month to DateTime Object
dt2 = dt2.AddMonths(1);
Response.Write(dt2.ToString() + "<br>");
//Output: 29-07-2007 10:11:00
//Example 7 : Adding Year to DateTime Object
dt2 = dt2.AddYears(1);
Response.Write(dt2.ToString() + "<br>");
//Output: 29-07-2008 10:11:00
//Examples of Retrieving DateTime object value.
//Example 1 : Get Day value.
int intDay = dt1.Day;
Response.Write(intDay.ToString() + "<br>");
//Output: 22
//Example 2 : Get Day of Week.
DayOfWeek dow = dt1.DayOfWeek;
Response.Write(dow.ToString() + "<br>");
//Output: Friday
//How to find whether day of week is sunday or saturday?
if(dow == DayOfWeek.Sunday dow == DayOfWeek.Saturday)
{
//Hurray its weekend.
}
//Example 3 : Get the Day of Year
int intYear = dt1.DayOfYear; //Similarly you can get Year value.
Response.Write(intYear.ToString() + "<br>");
//Output: 173
//Similarly you can get Hours, Minutes, Seconds, Milliseconds value.
//Conversion of String to DateTime
//Make use of Parse Method of DateTime to "Convert String to DateTime in .Net"
DateTime dt4 = DateTime.Parse("08/06/2007");
DateTime dt5 = DateTime.Parse("10/06/2007");
//Comparing Date
//How to Find whether both dates are equal or Not?
//How to compare two dates in .Net?
if (DateTime.Compare(dt4, dt5) == 0)
{
Response.Write("Both Dates are Equal" + "<br>");
}
else if (DateTime.Compare(dt4, dt5) < 0)
{
Response.Write(dt4.ToString() + " is Less than "
+ dt5.ToString() + "<br>");
}
else
{
Response.Write(dt4.ToString() + " is Greater than "
+ dt5.ToString() + "<br>");
}
//Output: 08-06-2007 00:00:00 is Less than 10-06-2007 00:00:00
/*Note: You may recieve error: "String was not recognized as a valid
DateTime." This may be occur as in India the DateTime format is followed
as "dd/mm/yyyy" But let say if you are in USA than it follow "mm/dd/yyyy" so here
there is crash situation and so you might recieve above error, so to avoid such
error make sure that user input valid date before you Parse date. */
//Difference between Date
//How to Find difference between two dates in .Net?
//How to Find days difference between two dates in .Net?
//How to subtract one date from another?
TimeSpan tsDiff = dt5.Subtract(dt4); //Note: Always subtract smaller date
//value from greater date
Response.Write("Difference between " + dt4.ToString() + " and " +
dt5.ToString() + " is " + tsDiff.Days.ToString() + " days." + "<br>");
//Output: Difference between 08-06-2007 00:00:00 and 10-06-2007 00:00:00 is 2 days.
//Similarly you can also find:
//How many hour difference between two dates
//How many seconds difference between two dates
//And so on... by changing tsDiff property value to hours, seconds....
//instead of tsDiff.Days.
//Compare Time
//How to Find whether both Time are equal or Not?
//How to compare Time in .Net?
dt4 = DateTime.Parse("4:30 AM");
dt5 = DateTime.Parse("7:30 PM");
if (DateTime.Compare(dt4, dt5) == 0)
{
Response.Write("Both Times are Equal" + "<br>");
}
else if (DateTime.Compare(dt4, dt5) < 0)
{
Response.Write(dt4.ToShortTimeString() + " is Less than "
+ dt5.ToShortTimeString() + "<br>");
}
else
{
Response.Write(dt4.ToShortTimeString() + " is Greater than "
+ dt5.ToShortTimeString() + "<br>");
}
//Output: 04:30:00 is Less than 19:30:00
//Difference between Time
//How to Find difference between two Time value in .Net?
//How to Find Hours difference between two Time in .Net?
//How to subtract one Time from another?
//How to find elapsed Time between Two Time value in .Net?
tsDiff = dt5.Subtract(dt4); //Note: Always subtract smaller date
//value from greater date
Response.Write("Difference between " + dt4.ToString() + " and " + dt5.ToString() + " is " + tsDiff.Hours.ToString() + " Hours." + "<br>");
//Output: Difference between 22-06-2007 04:30:00 and 22-06-2007 19:30:00 is 15 Hours.
//More on DateTime
//How many days in a given month in .Net?
int intDaysInMonth = DateTime.DaysInMonth(2007, 6); //Pass valid year, and month
Response.Write(intDaysInMonth.ToString() + "<br>");
//Output: 30
//How to find whether given year is Leap year or not in .Net?
Response.Write( DateTime.IsLeapYear(2007)); //Pass valid year
//Output: False
//How to find current date and time?
Response.Write("Current Date and Time: " + DateTime.Now + "<br>");
//Output: Current Date and Time: 22-06-2007 11:31:04
//How to find current date?
Response.Write("Current Date: " + DateTime.Today + "<br>");
//Output: Current Date: 22-06-2007 00:00:00

Thursday, August 13, 2009

Style Of C# Coding

Example Style if you have a long sql.

Not cool. Harder To see. Makes our head goes vertigo.

string selectSql = "SELECT MMIS_Login.uid, "MMIS_Personnel.person_id, MMIS_Personnel.first_name, MMIS_Personnel.last_name, MMIS_Personnel.division_id, MMIS_Login.email FROM MIS_Personnel INNER JOIN MMIS_Login ON MMIS_Personnel.person_id = MIS_Login.person_id WHERE (MMIS_Login.uid ='" + uid + "')";

Below is a right way.

string selectSql = "SELECT MMIS_Login.uid, " +
                   "MMIS_Personnel.person_id, " +
                   "MMIS_Personnel.first_name, " +
                   "MMIS_Personnel.last_name, " +
                   "MMIS_Personnel.division_id, " +
                   "MMIS_Login.email FROM MMIS_Personnel INNER JOIN " +
                   "MMIS_Login ON MMIS_Personnel.person_id = MIS_Login.person_id " +
                   "WHERE (MMIS_Login.uid ='" + uid + "')";

Wednesday, August 12, 2009

No mapping exists from object type System.Web.UI.WebControls.Label to a known managed provider native type.

 

If you come across this error below  in C# ASP.Net

“No mapping exists from object type System.Web.UI.WebControls.Label to a known managed provider native type.”

Turns out the reason this error showed up was I was trying to set the session variable equal to just the name of the label. So as an example I had this:

session["variable"] = lblName;

And it needed to be:

session["variable"] = lblName.Text;

Monday, August 10, 2009

Format Number As Currency String [C#.NET]

While in the Web Development / Windows applications, it is very helpful to the friendly currency values as $ 1345.00 instead of 1345. In C #. NET, it is easy to set up a series of string format, the currency with the method and the string.Format C

string.Format( "{0:C}", 123345);

Here is a fully functional sample code

    class Program
    {
        static void Main(string[] args)
        {
            int nPrice = 1234;
            string sString;
            //
            sString = string.Format("{0:C}", nPrice);
            //
            Console.WriteLine("Price: " + sString);
            Console.ReadLine();
        }
    }

Output
Price=$123,345.00

Change the default currency symbol

If you use the code example above, you may have a different icon in production than $. The symbol of string.Format depends on your operating system locale. For example, if the code of an operating system, configured with the regional Indian you have the result in R. 1235.00.

If necessary, you can set the currency to use string.Format by using NumberFormatException Info class. Here is an example that forces string.Format Pound as a currency symbol

System.Globalization.NumberFormatInfo nfi;
nfi = new NumberFormatInfo();
nfi.CurrencySymbol = "£";
sString = string.Format(nfi, "{0:C}", 123345);

Output
Price=£123,345.00

Wednesday, August 5, 2009

C# ASP.NET Datasets Error

Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.

this error message stated that related to primary key setup for the Data Table and also related to max length of a column in the datatable