Monday, September 15, 2008

Login Error in subreports with Crystal Reports

I am a fan of crystal reports. When ever it is feasible i want to use the Crystal report in my .net application whether it is window or web application. 
While working with one of my window application i got this weird error. It ask me for login in the database. That also happened with my reports which i changed recently.  The reports were working good till they were on my development system. It started giving problem when they are deployed on client machine. 
My client enviourment we have VS 2008 IDE too. So i opened the Report and went in the Dataset and check if it is pointing to correct XSD or not. I am using XSD (Type data set) in  all my crystal reports. Now when i click on the verify database the message came up "Data base is up to Date" . But after that the message box came up for selecting the XSD. I have selected the XSD and then the report start working as expected. 
With all these exercise i came to know that there is some problem with the XSD. The only way to find out the problem is this way
1) Open the .rpt file
2) Go to field Explorer
3) Right Click on database field and then Database Expert
4) Create New connection 
5) Click On ADO.net 
6) It will ask you to select the class
7) If you have some table already  selected then you can just right click the table and see the properties. if Visual Studio Data Class name  is set for the Local directory something like c:\project..
that is the root of the problem. So you have to make it from the project not from the local directory.

 

Wednesday, September 10, 2008

Distinct records in datatable

Here is the easiest way to create a table with the distinct records. I have to add the currency symbols with the Currency name in the brackets. If these currency name was not the constraint then it was be really easy for me to add the items in the Combobox. I was able to add the items in the comboox and before adding just giving this condition 
if (ddlCurrencySymbol.Items.Contains("Textvalue")) continue;
Solve my purpose. But now the problem was i have to add the Currency name also in the list. So i can't just adding the name and use the above condition because it will create Euro for many countries. 

Now here what i have done to solve this issue.
I create two functions and use them to get rid of the Extra values.

public void SelectDistinctCurrency(string TableName, DataTable Table1, string CurrencyName)
        {
            DataTable dt = new DataTable(TableName);
            dt.Columns.Add(CurrencyName, SourceTable.Columns[CurrencyName].DataType);
            dt.Columns.Add("Text", SourceTable.Columns[CurrencyName].DataType);
            object FinalValue= null;
            foreach (DataRow dr in SourceTable.Select("", CurrencyName))
            {
                if (FinalValue == null || !(ColumnEqual(FinalValue, dr[FieldName])))
                {
                    FinalValue = dr[CurrencyName];
                    dt.Rows.Add(new object[] { FinalValue, dr["Text"] });
                }
            }
            ddlCurrencySymbol.DataSource = dt;
            ddlCurrencySymbol.DisplayMember = "Text";
            ddlCurrencySymbol.ValueMember = "Value";
        }
        private bool ColumnEqual(object A, object B)
        {

            if (A == DBNull.Value && B == DBNull.Value) 
                return true;
            if (A == DBNull.Value || B == DBNull.Value) 
                return false;
            return (A.Equals(B));  
        }

Hope this will hep you out.

Tuesday, September 9, 2008

Winform Size

Hi friends 
i fond one intresteing thing today. It was increaing the height of the window form in Visual studio. I have oen collegue he cam up with unique problem. he ask me how to increase the size of the Window form in the VS. The obvoius answer was just go to properties and add the number and the form will increase of that size. But to my surprize what ever value we enter it will revert back to 768 Pixel.  Now how to increase in the size if i want that to 1000. 
The trick was just  change the resolution of your system and then increae the size. now revert back to old resolution this increased sized won't revert back. It will remain 1000 Pixel only :)