Buscar contenidos

miércoles, 20 de julio de 2016

Ejemplo C#,RDLC,ASPX,ReportViewer

Fuente

What is the difference between RDL and RDLC formats?

I have always thought the different between RDL and RDLC is that RDL are used for SQL Server Reporting Services and RDLC are used in Visual Studio for client side reporting. The implemenation and editor are almost identical. RDL stands for Report Defintion Language and RDLC Report Definition Language Client-side.

A: RDL files are created by the SQL Server 2005 version of Report Designer. RDLC files are created by the Visual Studio 2008 version of Report Designer.
RDL and RDLC formats have the same XML schema. However, in RDLC files, some values (such as query text) are allowed to be empty, which means that they are not immediately ready to be published to a Report Server. The missing values can be entered by opening the RDLC file using the SQL Server 2005 version of Report Designer. (You have to rename .rdlc to .rdl first.)
RDL files are fully compatible with the ReportViewer control runtime. However, RDL files do not contain some information that the design-time of the ReportViewer control depends on for automatically generating data-binding code. By manually binding data, RDL files can be used in the ReportViewer control. New! See also the RDL Viewer sample program.
Note that the ReportViewer control does not contain any logic for connecting to databases or executing queries. By separating out such logic, the ReportViewer has been made compatible with all data sources, including non-database data sources. However this means that when an RDL file is used by the ReportViewer control, the SQL related information in the RDL file is simply ignored by the control. It is the host application's responsibility to connect to databases, execute queries and supply data to the ReportViewer control in the form of ADO.NET DataTables.


Cuando usar un SqlCommand o un SqlDataAdapter

Fuente

Un SqlCommand se utiliza cuando necesitas ejecutar un tipo de sentencia Sql a la base de datos (los tipos pueden ser: Delete, Update, Insert o Select). Por su parte el SqlDataAdapter se utiliza si requieres ejecutar más de un tipo de sentencia Sql o si trabajarás en escenarios desconectados.
Ejemplo de SqlCommand:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
public List Listar()
{
    SqlConnection con = new SqlConnection(cadenaConexion);
    SqlCommand com = new SqlCommand("LISTAR_CAMPANAS", con);
    com.CommandType = System.Data.CommandType.StoredProcedure;
 
    con.Open();
 
    SqlDataReader drCampanas = com.ExecuteReader();
    List listaCampanas = new List();
 
    while (drCampanas.Read())
    {
        listaCampanas.Add(Cargar(drCampanas));
    }
 
    drCampanas.Close();
    con.Close();
    return listaCampanas;
}
Ejemplo de SqlDataAdapter (basado en el ejemplo anterior pero levemente modificado):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
public List Listar()
{
SqlConnection con = new SqlConnection(cadenaConexion);
SqlCommand com = new SqlCommand("LISTAR_CAMPANAS", con);
com.CommandType = System.Data.CommandType.StoredProcedure;
SqlDataAdapter da = new SqlDataAdapter(com);
con.Open();
 
SqlDataReader drCampanas = da.SelectCommand.ExecuteReader();
List listaCampanas = new List();
 
while (drCampanas.Read())
{
listaCampanas.Add(Cargar(drCampanas));
}
 
drCampanas.Close();
con.Close();
return listaCampanas;
}
En el ejemplo anterior se muestra como un SqlDataAdapter puede contener a un SqlCommand (llamado “com” en el ejemplo) que representa una sentencia Select; de igual forma, se puede agregar comandos que representen las sentencias Insert, Update y Delete utilizando sus respectivas propiedades:
1
2
3
4
SqlCommand dummyCommand = new SqlCommand();
da.UpdateCommand = dummyCommand;
da.DeleteCommand = dummyCommand;
da.InsertCommand = dummyCommand;
Si no necesitas trabajar en escenarios desconectados y si solo necesitas utilizar un comando a la vez, utiliza un SqlCommand, de lo contrario un SqlDataAdapter.