Showing posts with label .Net Interview Questions. Show all posts
Showing posts with label .Net Interview Questions. Show all posts

Friday, 11 November 2011

Crystal Report Basic Sample

 
7 Easy Steps to get start with Crystal Report.


To Start With You Shold Have A Table In your Database.





Before I start I would like to recommend new kind of reporting which is which is currently a hot topic in IT industry, that is Power bi,and you can head start with it by viewing this popular video on power bi which can make you power bi professional in very simple stepsas below.




1)Open visual studio...then create website

2)Now open  toolbox,go on Reporting TAB,Add Crystal Report Viewer To Any Of Your Blank ASPX page,
(if only Pointer And MicrosoftViewer Is Present or If Crystal Report Is Not Existed In the Reporting TAB.Go through the VISUAL STUDIO SET UP AGAIN AND CHOOSE  ADD NEW ITEM instead of UPDATE OPTION THIS TIME and you'll see in the installation list crystal report is in the last!)



2)Now After You Drag The Crystal Report Viewer Control you'll get a control in your page with name 'CrystalReportViewer1')

Now right click to your solution add new item and select CrystalReport.this will add crystal report to  your solution (as you add webform or any file) wth name 'CrystalReport.rpt'

Now You Have
a Crystal Report (CrystalReport.rpt)
And
a Crystal Report Control (CrystalReportViewer1)In a Form Who Can Handle It.




3)Now When You Open Crystal Report  The Screen Will Look Some Thing Like This



 
4)Now You’ll Find Field Explorer side bar in right with solution Explorer As Shown open it and right click Database Field




5) After That A New Window Will open ‘DATABASE EXPERT’

Now Here  Is The Thing You Have To Go Smoothly.
Click ‘create new connection’ + sign
then + sign of OL EDB ADO



then a window will appear which wil ask you to set your database path...

make proper connection…
After that your database will get generate on right hand side pane.





Click > and transfer your database to 'selected table' box(on right hand side)
Click table name press ok

and you have done 90% of work!






6)
Now just Explore database field of field explorer(Field Explorer  Only Appears in CrytalReport) and drag coloumn name to the Crystal report .
wherever you want
(Coloum automaticly behave as they are bind in gridview or datalist)




Check the toolbox you have four tools to design.










7)
Write this code in form .cs file where the control exist

i)add these namespaces must


using System.IO;
using System.Data.SqlClient;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using CrystalDecisions.Enterprise;
using CrystalDecisions.ReportSource;



ii)and continue to this as you understand

Now the basic thing you have to do is Binding Your Database Value to Crystal Report!
if You Understand the basic binding you can easily notice that i 've just binded values to crytal report!


public void NormalBinding()
{

SqlCommand sqlcmd = new SqlCommand("
select * from sample", con);SqlDataAdapter  da = new SqlDataAdapter(sqlcmd); 
DataTable dt = new DataTable();
dt.Clear();
da.Fill(dt);


if (dt.Rows.Count > 0)
{
ReportDocument RptDoc = new ReportDocument();

RptDoc.Load(Server.MapPath("CrystalReport.rpt"));
RptDoc.SetDataSource(dt);

CrystalReportViewer1.ReportSource = RptDoc;
CrystalReportViewer1.DataBind();

}

                            



Above one is all about a function  NormalBinding() who's used to bind data in crystal report!      
you can take a look to basic binding on my basic asp.net post.



Now Your Whole Project Will Look Some thing Like This.

.ASPX PAGE
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="crys.aspx.cs" Inherits="_Default" %>

<%@ Register Assembly="CrystalDecisions.Web, Version=10.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"
    Namespace="CrystalDecisions.Web" TagPrefix="CR" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="true" />
    </div>
    </form>
   
</body>
</html>

.CS FILE
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Data.OleDb;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.IO;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using CrystalDecisions.Enterprise;
using CrystalDecisions.ReportSource;
public partial class _Default : System.Web.UI.Page
{
    SqlConnection sconn = new SqlConnection(ConfigurationManager.AppSettings["regattacon"]);
    string sid;
    SqlDataAdapter da;
    string query;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
         
            bindproformainvoicepi_no();

        }
    }

    public void bindproformainvoicepi_no()
    {

        query = "select * from sample";
        SqlCommand sqlcmd = new SqlCommand(query, sconn);

        da = new SqlDataAdapter(sqlcmd); DataTable dt = new DataTable();
        dt.Clear();
        da.Fill(dt);
        if (dt.Rows.Count > 0)
        {
            ReportDocument RptDoc = new ReportDocument();

            RptDoc.Load(Server.MapPath("CrystalReport.rpt"));
            RptDoc.SetDataSource(dt);

            CrystalReportViewer1.ReportSource = RptDoc;
            CrystalReportViewer1.DataBind();
          


        }
    }
}






RUN it and have fun with CRYSTAL REPORT,with its nice printing,exporting to excel,pdl,doc ,style












Thursday, 28 July 2011

.Net Interview Question Level 1



Basic Interview Question .Net
Few very basic question you need to keep in mind in interview of asp.net  where database is sql.you should be more curious toward each question to arise few more question from them.i have posted some in below of the post



1) Difference between a primary key and a unique key in SQL? 

primary key doesn't allow duplicate values and does not allow null.
unique key also doesnot allow duplicate values but allows one null value

2) difference between asp and asp.net 

The .NET compliant languages can be used with ASP.NET like C# and VB.NET, where both of them are server-sided languages. With ASP, only VBScript and JavaScript are available as options to be used.  

 

3) What are the new features in ASP.net 3.5 

The most significant improvements in ASP.NET are:

* Integrated Ajax Support
* New Data Controls (ListView and DataPager)
* The LinqDataSource Control

Visual Studio 2008 has also included some features for an improved web application development experience. Here is the list of such improvements:

* Support for LINQ
* IntelliSense for JavaScript and ASP.NET Ajax
* Improved Design time experience

4) Choosing a Web Service or .Net Remoting in projects?

Well Web services uses .Net remoting concepts internally. But the major difference between web service and .net remoting is that “web service” can be consumed by clients who are not .NET platform. While remoting you need the client to be .NET compliant.

Regarding the speed issue ".net Remoting" is faster than “Web Services”. So I think when deciding the architecture side of choosing between “Web services” and “.NET Remoting” keep the cross platform issue and the speed issue in mind. 

 

5) Difference between DataSet and DataReader? 

DataSet is a disconnected architecture, while DataReader has live connection while reading data. If we want to cache data and pass to a different tier DataSet forms the best choice and it has decent XML support.

When application needs to access data from more than one table DataSet forms the best choice.

If we need to move back while reading records, datareader does not support this functionality.

One of the biggest drawbacks of DataSet is speed. As DataSet carry considerable overhead because of relations, multiple tables etc speed is slower than DataReader. Always try to use DataReader wherever possible, as it’s meant specially for speed performance. 

 

6) What is the difference between Hash Table and Arrays?

 1.Array is a collection of same datatype
while

arrays are objects that derive from the base Array class and implement IEnumerable so that array elements can be enumerated with a For-Each loop.

2.Hash table is a colletion of different datatype. 

Hash tables hold a collection of DictionaryEntry objects, where a DictionaryEntry holds the Key along with its value.

7) Difference between C# and C programming Language? 

C# does not usually make use of pointers. You can only increment, or decrement a variable as if it were an actual memory pointer inside a special unsafe block.

You can declare variables anywhere inside a method you want to; they don’t have to be at the beginning of the method.


You don’t have to declare an object before you use it; you can define it just as you need it.

C# has a somewhat different definition of the struct types, and does not support the idea of a union at all.

C# has enumerated types, which allow a series of named values, such as colors or day names, to be assigned sequential numbers, but the syntax is rather different.

C# does not have bit fields: variables that take up less than a byte of storage.

C# does not allow variable length argument lists. You have to define a method for each number and type of argument. However C# allows for the last argument of a function to be a variable parameter array.
 


Few more on above 7 question  you can explore...

1)foreign key?relation with foreign key?

2)MVC?

3).net 4.0 and further

4)WCF basic concept

5)disconnected and connected architecture

6)dictionary

7)c++ 




Print Only Grid View in ASP.net

ASP.net How to Print Only GridView < div id ="gridviewDiv" >   < asp:GridView ID ="gridViewToPri...