domingo, 17 de octubre de 2010
Convertir Linq a un DataTable ( LINQ To DataTable)
Yo sé que Ado .net está obsoleto, aun así puede llegar hacer útil, sin embargo les sigo recomendando que usen linq o entity, se los juro van a trabajar menos.
DataClassesDataContext db = new DataClassesDataContext();
var query= from c in db.Customers
select new {c.CustomerID, c.CompanyName, c.ContactName, c.Country,c.City };
IDbCommand cmd = db.GetCommand(query as IQueryable);
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = (SqlCommand)cmd;
DataTable dt = new DataTable("sd");
try
{
cmd.Connection.Open();
adapter.FillSchema(dt, SchemaType.Source);
adapter.Fill(dt);
}
finally
{
cmd.Connection.Close();
}
Ver
DataClassesDataContext db = new DataClassesDataContext();
var query= from c in db.Customers
select new {c.CustomerID, c.CompanyName, c.ContactName, c.Country,c.City };
IDbCommand cmd = db.GetCommand(query as IQueryable);
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = (SqlCommand)cmd;
DataTable dt = new DataTable("sd");
try
{
cmd.Connection.Open();
adapter.FillSchema(dt, SchemaType.Source);
adapter.Fill(dt);
}
finally
{
cmd.Connection.Close();
}
sábado, 16 de octubre de 2010
Llamar todos los reportes desde una aspx
HTML de la pagina:
Necesitaran esta clase:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Reporting.WebForms;
using System.Net;
using System.Security;
using System.Security.Principal ;
using System.Configuration;public partial class ReportViewerCredentials : IReportServerCredentials
{
private string _userName;
private string _password;
private string _domain;
public ReportViewerCredentials(string userName, string password, string domain)
{
_userName = userName;
_password = password;
_domain = domain;
}
public WindowsIdentity ImpersonationUser {
get {
return null;
}
}
public ICredentials NetworkCredentials {
get {
return new NetworkCredential(_userName, _password, _domain);
}
}
public bool GetFormsCredentials(out Cookie authCookie,
out string userName, out string password,
out string authority)
{
authCookie = null;
userName = _userName ;
password = _password ;
authority = _domain ;
// Not using form credentials
return false;
}
}
Código de la pagina, en el evento Load.
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
string Reporte = "";
Reporte = Request.QueryString["Reporte"].ToString();
rvReportes.ServerReport.ReportServerUrl = new Uri(http://pc/ReportServer);
rvReportes.ServerReport.ReportPath = Reporte;
ReportParameter _param_1 = new ReportParameter("codigo", "123",false);
this.rvReportes.ShowCredentialPrompts = false;
this.rvReportes.ServerReport.ReportServerCredentials = new ReportViewerCredentials("Usuario", "Contraseña", "pc");
this.rvReportes.ServerReport.SetParameters(new ReportParameter[] { _param_1 });
this.rvReportes.ServerReport.Refresh();
}
}
Ver
Necesitaran esta clase:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Reporting.WebForms;
using System.Net;
using System.Security;
using System.Security.Principal ;
using System.Configuration;public partial class ReportViewerCredentials : IReportServerCredentials
{
private string _userName;
private string _password;
private string _domain;
public ReportViewerCredentials(string userName, string password, string domain)
{
_userName = userName;
_password = password;
_domain = domain;
}
public WindowsIdentity ImpersonationUser {
get {
return null;
}
}
public ICredentials NetworkCredentials {
get {
return new NetworkCredential(_userName, _password, _domain);
}
}
public bool GetFormsCredentials(out Cookie authCookie,
out string userName, out string password,
out string authority)
{
authCookie = null;
userName = _userName ;
password = _password ;
authority = _domain ;
// Not using form credentials
return false;
}
}
Código de la pagina, en el evento Load.
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
string Reporte = "";
Reporte = Request.QueryString["Reporte"].ToString();
rvReportes.ServerReport.ReportServerUrl = new Uri(http://pc/ReportServer);
rvReportes.ServerReport.ReportPath = Reporte;
ReportParameter _param_1 = new ReportParameter("codigo", "123",false);
this.rvReportes.ShowCredentialPrompts = false;
this.rvReportes.ServerReport.ReportServerCredentials = new ReportViewerCredentials("Usuario", "Contraseña", "pc");
this.rvReportes.ServerReport.SetParameters(new ReportParameter[] { _param_1 });
this.rvReportes.ServerReport.Refresh();
}
}
Suscribirse a:
Entradas (Atom)