*********************************************************************************
Most valuable method No need giving local path:
*********************************************************************************
through dataset u can achieve this:
1) To add crystalreportviewer in windows form
2)To Add the following name space
using CrystalDecisions.CrystalReports.Engine;
private void Form1_Load(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection("provider=sqloledb;server=.;database=northwind;integrated security=sspi");
con.Open();
OleDbDataAdapter ada = new OleDbDataAdapter("SELECT * FROM EMPLOYEES", con);
DataSet ds = new DataSet();
ada.Fill(ds);
for (int i = 0; i < ds.Tables[0].Rows.Count-1; i++)
{
comboBox1.Items.Add(ds.Tables[0].Rows[i][0].ToString());
}
}
private void button1_Click(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection("provider=sqloledb;server=.;database=northwind;integrated security=sspi");
con.Open();
OleDbDataAdapter ada = new OleDbDataAdapter("SELECT * FROM EMPLOYEES WHERE EMPLOYEEID='" + comboBox1.Text.ToString() + "' ", con);
DataSet ds = new DataSet();
ada.Fill(ds);
CrystalReport4 cra = new CrystalReport4();
cra.SetParameterValue("@id", ds.Tables[0].Rows[0][0].ToString());
cra.SetParameterValue("@name", ds.Tables[0].Rows[0][1].ToString());
cra.SetParameterValue("@title", ds.Tables[0].Rows[0][2].ToString());
crystalReportViewer1.ReportSource = cra;
}
3)In crystalrepor.rpt do the following things
i)Select Blank report
ii) In the field explorer select parameter
iii)add new parameter according to setparamervalues("@id",dr[0].ToString()).
================================================================
************************************************************
Best Way To show crystal report in windows application
*************************************************************
1) To add crystalreportviewer in windows form
2)To Add the following name space
using CrystalDecisions.CrystalReports.Engine;
To Load Id values in combobox with help of following code:
private void Form2_Load(object sender, EventArgs e)
{
OleDbCommand cmd = new OleDbCommand("SELECT EMPLOYEEID FROM EMPLOYEES", con);
con.Open();
dr = cmd.ExecuteReader();
while (dr.Read())
{
comboBox1.Items.Add(dr[0].ToString());
}
dr.Close();
con.Close();
}
To add following code in button event
private void button1_Click(object sender, EventArgs e)
{
ReportDocument rep = new ReportDocument();
rep.Load ("D:\\VIVEK\\Practise\\crystalreport\\crystalreport\\CrystalReport3.rpt");
con.Open();
cmd1 =new OleDbCommand ("SELECT * FROM EMPLOYEES where EMPLOYEEID='"+comboBox1 .Text +"'", con);
dr=cmd1.ExecuteReader ();
if (dr.Read ())
{
rep.SetParameterValue ("@id",dr[0].ToString());
rep.SetParameterValue("@name", dr[1].ToString());
rep.SetParameterValue("@title", dr[2].ToString());
}
dr.Close();
con.Close();
crystalReportViewer1.ReportSource = rep;
}
3)In crystalrepor.rpt do the following things
i)Select Blank report
ii) In the field explorer select parameter
iii)add new parameter according to setparamervalues("@id",dr[0].ToString()).
Now u can get desired values according to ur selection
================================================
CRYSTAL REPORT USING DATASET
==============================================
WINDOWS APPLICATION
==============================
- ADD A DATASET
- IN THAT DATASET RIGHT CLICK AND CHOOSE DATA TABLE.
- IN THAT DATATALE RIGHT CLICK AND ADD COLUMN(GIVE DATABASE TABLE COLUMN NAMES AS DATATABLE COLUMN NAME) ANT THEN SAVE
-ADD CRYSTAL REPORT AND CHOOSE AS BLANK REPORT
-THEN IN THAT CRYSTAL REPORT GOTO FILED EXPLORER AND THEN RIGHT CLIK IN DATABASE FIELDS->
CHOOSE DATABASE EXPERT
- THEN A WIZARD IS COME THEN GOTO PROJECT DATA->ADO.NET DATASETS->CHOOSE OUR DATATABLE->CLICK >> -> CLICK FINISH
-------------------------
IN FORM
-ADD A COMBOBOX
-ADD A CRYSTAL REPORT VIEWER
-ADD using System.Data.SqlClient;
using CrystalDecisions.CrystalReports.Engine;
SqlConnection con = new SqlConnection("server=.;database=sam;integrated security=true");
SqlCommand cmd;
SqlDataReader dr;
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
private void Form1_Load(object sender, EventArgs e)
{
cmd = new SqlCommand("select distinct(idd) from a", con);
con.Open();
dr = cmd.ExecuteReader();
while (dr.Read())
{
comboBox1.Items.Add(dr[0].ToString());
}
dr.Close();
con.Close();
}
============================================
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
da = new SqlDataAdapter("select * from a where idd='" + comboBox1.SelectedItem.ToString() + "'", con);
ds.Clear();
da.Fill(ds, "dt");//DT IS DATATABLE NAME IN DATASET
CrystalReport1 c = new CrystalReport1();
c.SetDataSource(ds);
crystalReportViewer1.ReportSource = c;
}
====================================
WEB APPLICATION
=========================
ADD A DATASET
- IN THAT DATASET RIGHT CLICK AND CHOOSE DATA TABLE.
- IN THAT DATATALE RIGHT CLICK AND ADD COLUMN(GIVE DATABASE TABLE COLUMN NAMES AS DATATABLE COLUMN NAME) ANT THEN SAVE
-ADD CRYSTAL REPORT AND CHOOSE AS BLANK REPORT
-THEN IN THAT CRYSTAL REPORT GOTO FILED EXPLORER AND THEN RIGHT CLIK IN DATABASE FIELDS->
CHOOSE DATABASE EXPERT
- THEN A WIZARD IS COME THEN GOTO PROJECT DATA->ADO.NET DATASETS->CHOOSE OUR DATATABLE->CLICK >> -> CLICK FINISH
===================================
IN PAGE
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.ReportSource;
using System.Data.SqlClient;
SqlConnection con = new SqlConnection("server=.;database=sam;integrated security=true");
SqlCommand cmd;
SqlDataReader dr;
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
protected void DropDownList1_Init(object sender, EventArgs e)
{
cmd = new SqlCommand("select distinct(idd) from a", con);
con.Open();
dr = cmd.ExecuteReader();
while (dr.Read())
{
DropDownList1.Items.Add(dr[0].ToString());
}
dr.Close();
con.Close();
}
====================================
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
da = new SqlDataAdapter("select * from a where idd='" + DropDownList1.SelectedItem.ToString() + "'", con);
ds.Clear();
da.Fill(ds, "dt");
ReportDocument r = new ReportDocument();
r.Load(Server.MapPath("CrystalReport.rpt"));
r.SetDataSource(ds);
CrystalReportViewer1.ReportSource = r;
}
====================================
URLS
http://www.beansoftware.com/ASP.NET-Tutorials/Using-Crystal-Reports.aspx
http://forums.asp.net/76.aspx
http://www.highoncoding.com/Articles/550_Creating_Crystal_Report_in_ASP_NET.aspx
http://www.c-sharpcorner.com/UploadFile/rsubhajit/CrystalReportwithDataSet03012006060655AM/CrystalReportwithDataSet.aspx
http://aspalliance.com/776
http://www.aspfree.com/c/a/ASP.NET/Working-with-ADONET-Datasets-and-NET-Objects-using-Crystal-Reports-and-ASP-NET-2-0/1/
http://www.codeproject.com/KB/aspnet/crystal_report.aspx
Hunt
Saturday, February 27, 2010
Tuesday, February 16, 2010
DIFFERNECES..
DIFFERENCE BETWEEN DATAREADER AND DATASET
===================================================
Answer:
DataReader
===========
DataReader is like a forward only recordset. It fetches one row at a time so very less network cost compare to DataSet(Fethces all the rows at a time). DataReader is readonly so we can't do any transaction on them. DataReader will be the best choice where we need to show the data to the user which requires no transaction. As DataReader is forward only so we can't fetch data randomly. .NET Data Providers optimizes the datareader to handle huge amount of data.
DataSet
=======
DataSet is an in memory representation of a collection of Database objects including tables of a relational database schemas.
DataSet is always a bulky object that requires a lot of memory space compare to DataReader. We can say that the DataSet is a small database because it stores the schema and data in the application memory area. DataSet fetches all data from the datasource at a time to its memory area. So we can traverse through the object to get the required data like querying database.
URL:
http://www.dotnetfunda.com/interview/exam13-difference-between-dataset-and-datareader.aspx
A DataReader works in a connected environment, whereas DataSet works in a disconnected environment.
A DataReader object represents a forward only, read only access to data from a source. It implements IDataReader & IDataRecord interfaces. For example, The SQLDataReader class can read rows from tables in a SQL Server data source. It is returned by the ExecuteReader method of the SQLCommand class, typically as a result of a SQL Select statement. The DataReader class' HasRows property can be called to determine whether the DataReader retrieved any rows from the source. This can be used before using the Read method to check whether any data has been retrieved.
Example
Dim objCmd as New SqlCommand("Select * from t_Employees", objCon)
objCon.Open()
Dim objReader as SqlDataReader
objReader = objCom.ExecuteReader(CommandBehavior.CloseConnection)
If objReader.HasRows = True then
Do While objReader.Read()
ListBox1.Items.Add(objReader.GetString(0) & vbTab & objReader.GetInt16(1))
Loop
End If
objReader.Close()
(NOTE: XmlReader object is used for Forward only Read only access of XML).
A DataSet represents an in-memory cache of data consisting of any number of inter-related DataTable objects. A DataTable object represents a tabular block of in-memory data. Further, a DataRow represents a single row of a DataTable object. A Dataset is like a mini-database engine, but its data is stored in the memory. To query the data in a DataSet, we can use a DataView object.
Example
Dim objCon as SqlConnection = New SqlConnection("server=(local);database=NameOfYourDb;user id=sa; password=;)
Dim da as New SqlDataAdapter
Dim ds as DataSet = New DataSet
da.SelectCommand.Connection = objCon 'The Data Adapter manages on its own, opening & closing of connection object
da.SelectCommand.CommandText = "Select * from t_SomeTable"
da.Fill(ds,"YourTableName")
Suppose you want to bind the data in this dataset to a gridview
Gridview1.DataSource = ds
Gridview1.DataMember = "YourTableName"
Gridview1.Databind()
URL
http://www.dotnetuncle.com/Difference/111_DataReader_Dataset.aspx
================================================================================
Difference between Repeater, Datalist and GridView Control
URL:http://www.dotnetspider.com/resources/29917-Difference-between-Repeater-Datalist.aspx
In ASP .NET basically there are 3 kinds of the Data Presentation Controls.
1. GridView (or DataGrid) control
2. DataList control
3. Repeater control
When we talk about usage of one Data Presentation Controls then many of us get confused about choosing one. When you need to use one of the data Presentation Control then You have to see what kind of behavior you need in your Data Display.
1. Do you want to show Data in many Pages or in one page?
2. Do you have to Display more then one column in a Row ?
3. Do you want to have a Row repeating Possibility?
4. Will users be able to update, Insert and delete the Data?
Features of a GridView
•Displays data as a table
•Control over
–Alternate item
–Header
–Footer
–Colors, font, borders, etc.
–Paging
•Updateable
•Item as row
Features of Repeater
•List format
•No default output
•More control
•More complexity
•Item as row
•Not updateable
Features of DataList
•Directional rendering
•Good for columns
•Item as cell
•Alternate item
•Updateable
==========================================================
DIFFERNCE BETWEEN DATATABLE AND DATASET
A DataSet is an in memory representation of data,It containing one or more DataTables.
A DataTable is an in-memory representation of data, typically retrieved from a database or XML source.
A Dataset is like a Container for Datatables because every dataset has a datatable contained inside it and a Datatable is like a table you have in SQL and a Dataset its like a Database that contain table(Datatable)
URL
http://www.dotnetfunda.com/forums/thread615-what-is-the-difference-between-datatable-and-dataset.aspx
==============================================================================
===================================================
Answer:
DataReader
===========
DataReader is like a forward only recordset. It fetches one row at a time so very less network cost compare to DataSet(Fethces all the rows at a time). DataReader is readonly so we can't do any transaction on them. DataReader will be the best choice where we need to show the data to the user which requires no transaction. As DataReader is forward only so we can't fetch data randomly. .NET Data Providers optimizes the datareader to handle huge amount of data.
DataSet
=======
DataSet is an in memory representation of a collection of Database objects including tables of a relational database schemas.
DataSet is always a bulky object that requires a lot of memory space compare to DataReader. We can say that the DataSet is a small database because it stores the schema and data in the application memory area. DataSet fetches all data from the datasource at a time to its memory area. So we can traverse through the object to get the required data like querying database.
URL:
http://www.dotnetfunda.com/interview/exam13-difference-between-dataset-and-datareader.aspx
A DataReader works in a connected environment, whereas DataSet works in a disconnected environment.
A DataReader object represents a forward only, read only access to data from a source. It implements IDataReader & IDataRecord interfaces. For example, The SQLDataReader class can read rows from tables in a SQL Server data source. It is returned by the ExecuteReader method of the SQLCommand class, typically as a result of a SQL Select statement. The DataReader class' HasRows property can be called to determine whether the DataReader retrieved any rows from the source. This can be used before using the Read method to check whether any data has been retrieved.
Example
Dim objCmd as New SqlCommand("Select * from t_Employees", objCon)
objCon.Open()
Dim objReader as SqlDataReader
objReader = objCom.ExecuteReader(CommandBehavior.CloseConnection)
If objReader.HasRows = True then
Do While objReader.Read()
ListBox1.Items.Add(objReader.GetString(0) & vbTab & objReader.GetInt16(1))
Loop
End If
objReader.Close()
(NOTE: XmlReader object is used for Forward only Read only access of XML).
A DataSet represents an in-memory cache of data consisting of any number of inter-related DataTable objects. A DataTable object represents a tabular block of in-memory data. Further, a DataRow represents a single row of a DataTable object. A Dataset is like a mini-database engine, but its data is stored in the memory. To query the data in a DataSet, we can use a DataView object.
Example
Dim objCon as SqlConnection = New SqlConnection("server=(local);database=NameOfYourDb;user id=sa; password=;)
Dim da as New SqlDataAdapter
Dim ds as DataSet = New DataSet
da.SelectCommand.Connection = objCon 'The Data Adapter manages on its own, opening & closing of connection object
da.SelectCommand.CommandText = "Select * from t_SomeTable"
da.Fill(ds,"YourTableName")
Suppose you want to bind the data in this dataset to a gridview
Gridview1.DataSource = ds
Gridview1.DataMember = "YourTableName"
Gridview1.Databind()
URL
http://www.dotnetuncle.com/Difference/111_DataReader_Dataset.aspx
================================================================================
Difference between Repeater, Datalist and GridView Control
URL:http://www.dotnetspider.com/resources/29917-Difference-between-Repeater-Datalist.aspx
In ASP .NET basically there are 3 kinds of the Data Presentation Controls.
1. GridView (or DataGrid) control
2. DataList control
3. Repeater control
When we talk about usage of one Data Presentation Controls then many of us get confused about choosing one. When you need to use one of the data Presentation Control then You have to see what kind of behavior you need in your Data Display.
1. Do you want to show Data in many Pages or in one page?
2. Do you have to Display more then one column in a Row ?
3. Do you want to have a Row repeating Possibility?
4. Will users be able to update, Insert and delete the Data?
Features of a GridView
•Displays data as a table
•Control over
–Alternate item
–Header
–Footer
–Colors, font, borders, etc.
–Paging
•Updateable
•Item as row
Features of Repeater
•List format
•No default output
•More control
•More complexity
•Item as row
•Not updateable
Features of DataList
•Directional rendering
•Good for columns
•Item as cell
•Alternate item
•Updateable
==========================================================
DIFFERNCE BETWEEN DATATABLE AND DATASET
A DataSet is an in memory representation of data,It containing one or more DataTables.
A DataTable is an in-memory representation of data, typically retrieved from a database or XML source.
A Dataset is like a Container for Datatables because every dataset has a datatable contained inside it and a Datatable is like a table you have in SQL and a Dataset its like a Database that contain table(Datatable)
URL
http://www.dotnetfunda.com/forums/thread615-what-is-the-difference-between-datatable-and-dataset.aspx
==============================================================================
Subscribe to:
Posts (Atom)