recorrer dataset con procedimiento almacenado
-
martes, 16 de marzo de 2010 21:26
Como puedo recorrer un dataset con un procedimiento almacenado
el codigo que llevo hasta el momento es el siguiente, pero yo necesito que se me abra el crystal report pero en otra ventana, por que lo probe de otra forma pero dentro de mismo programa y salio pero desde otra ventana no sale. ayuda plis
private void btnVistaPrevia_Click(object sender, EventArgs e)
{
try
{
using (SqlConnection conn = new SqlConnection(conexion))
{
conn.Open();
SqlCommand cmd = new SqlCommand("SFAC_DetalleFactura", conn);
cmd.CommandType = CommandType.StoredProcedure;//Parametros de Entrada para el Sp
SqlParameter par_Correlativo = new SqlParameter("@fad_correlativo", SqlDbType.Int);
par_Correlativo.Value = 8730;
cmd.Parameters.Add(par_Correlativo);
//Parametreos de Salida
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
conn.Close();CrystalDecisions.CrystalReports.Engine.TextObject textObj;
CrystalDecisions.CrystalReports.Engine.ReportDocument CrystalD;
CrystalD.Load(@"C:\Desarrollo\Facturador Final3\Facturador Final3\CrystalPinesRecarga.rpt");
FrmReportes fr = new FrmReportes();
fr.Show();
crystalReportViewer2.ReportSource = CrystalD;
textObj = CrystalD.ReportDefinition.ReportObjects["Text1Encabezado"] as TextObject;
DataTable dt = ds.Tables[0];
textObj.Text = dt.Rows[0][1].ToString();crystalReportViewer2.RefreshReport();
conn.Close();
}
}
finally
{
}
}
Todas las respuestas
-
miércoles, 17 de marzo de 2010 0:11Moderadorhola
solo un comentario, estas necesitando mostrar otro formulario que tiene tu crystal report viewer y lo quieres general completo desde quine lo llama, digo en vez de traer la montaña porque no vas hasta ellas
que quiero decir, porque todo este codigo que estas usando no lo haces alli en mismo forma donde tienes el control de crystal, y desde la pagina que lo llamda le pasas el valor seelccionado por parametro
en tu caso solo deberias pasarle el valor de par_Correlativo, que encima segun veo es un valor fijo
en el form del reporte crea una propiedad y luego desde este form qu elo invica le pasas el valor, pero solo este es simple, y todo este coddigo lo ahces en el form_load del form que tiene el control del reporte
ejemplo
en el form del reporte
public class FormReporte
{
private int _paracorrelativo;
public int ParCorrelativo
{
get{return _paracorrelativo;}
set _paracorrelativo=value;}
}
private void FormReporte_Load(...)
{
try
{
using (SqlConnection conn = new SqlConnection(conexion))
{
conn.Open();
SqlCommand cmd = new SqlCommand("SFAC_DetalleFactura", conn);
cmd.CommandType = CommandType.StoredProcedure;
//Parametros de Entrada para el Sp
SqlParameter par_Correlativo = new SqlParameter("@fad_correlativo", SqlDbType.Int);
par_Correlativo.Value = this.ParCorrelativo ;
cmd.Parameters.Add(par_Correlativo);
//Parametreos de Salida
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
conn.Close();
CrystalDecisions.CrystalReports.Engine.TextObject textObj;
CrystalDecisions.CrystalReports.Engine.ReportDocument CrystalD;
CrystalD.Load(@"C:\Desarrollo\Facturador Final3\Facturador Final3\CrystalPinesRecarga.rpt");
FrmReportes fr = new FrmReportes();
fr.Show();
crystalReportViewer2.ReportSource = CrystalD;
textObj = CrystalD.ReportDefinition.ReportObjects["Text1Encabezado"] as TextObject;
DataTable dt = ds.Tables[0];
textObj.Text = dt.Rows[0][1].ToString();
crystalReportViewer2.RefreshReport();
conn.Close();
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
}
}
}
y desde el form que ahora estas invocando solo haces
public class FromInvicador
{
private void btnVistaPrevia_Click(object sender, EventArgs e)
{
FormReporte frm = new FormReporte();
frm.ParCorrelativo = 8730;
frm.Show();
}
}
eso es todo asi de simple sin tener que complciarse con el acceso de un form a otro, le pasas el valro de un form, y luego cada uno trabaj localmente cn sus controles
saludos
Leandro Tuttini
Blog
Buenos Aires
Argentina -
miércoles, 17 de marzo de 2010 12:35Moderadorque tengas el conn.Open(); no indicas que tengas la cadena de conexion has podido inicializar el objeto conn si ningun connectionstring y por eso te indica ese error.
Para el correcto funcionamiento, y que otros usuarios se puedan beneficiar de la solucion de esta pregunta por favor marca las respuestas que te hayan ayudado como "Respuesta".
Si la respuesta te ha sido util Votala.
Mi Blog: Jtorrecilla
Enlace a Faq de Winforms en Ingles Muy bueno -
miércoles, 17 de marzo de 2010 18:17Solamente ahora me falta si alguien me pudiera ayudar, o mejor creo otro post?? bueno ahi ustedes me indican, los valores que guarde en variables cada variable posee un control, por lo que en la factura hay que sumar, multiplicar, dividir y otras cosas mas, bueno eso como se hace o me pueden indicar alguna pagina para aprender a hacer eso.
-
miércoles, 17 de marzo de 2010 19:10ModeradorHola Benjamin no se para que utilizas todo este bloque:string Colum0 = dt.Rows[0][0].ToString();
string Colum1 = dt.Rows[0][1].ToString();
string Colum2 = dt.Rows[0][2].ToString();
string Colum3 = dt.Rows[0][3].ToString();
string Colum4 = dt.Rows[0][4].ToString();
string Colum5 = dt.Rows[0][5].ToString();
string Colum6 = dt.Rows[0][6].ToString();
string Colum7 = dt.Rows[0][7].ToString();
string Colum8 = dt.Rows[0][8].ToString();
string Colum9 = dt.Rows[0][9].ToString();
string Colum10 = dt.Rows[0][10].ToString();
string Colum11 = dt.Rows[0][11].ToString();
string Colum12 = dt.Rows[0][12].ToString();
string Colum13 = dt.Rows[0][13].ToString();
string Colum14 = dt.Rows[0][14].ToString();
string Colum15 = dt.Rows[0][15].ToString();
string Colum16 = dt.Rows[0][16].ToString();
string Colum17 = dt.Rows[0][17].ToString();Podrias indicarme?
Para el correcto funcionamiento, y que otros usuarios se puedan beneficiar de la solucion de esta pregunta por favor marca las respuestas que te hayan ayudado como "Respuesta".
Si la respuesta te ha sido util Votala.
Mi Blog: Jtorrecilla
Enlace a Faq de Winforms en Ingles Muy bueno -
miércoles, 17 de marzo de 2010 19:38Aqui yo guarde los valores de la consulta que me estrae el sp, los valores de la tablas
-
miércoles, 17 de marzo de 2010 20:02Moderadory donde los utilizas luego?es que me parece raro que declares 18 variables de tipo string para hacer eso
Para el correcto funcionamiento, y que otros usuarios se puedan beneficiar de la solucion de esta pregunta por favor marca las respuestas que te hayan ayudado como "Respuesta".
Si la respuesta te ha sido util Votala.
Mi Blog: Jtorrecilla
Enlace a Faq de Winforms en Ingles Muy bueno -
miércoles, 17 de marzo de 2010 20:14ModeradorEs mas te diria que si se las vas a pasar al crystal, q no veo en ese trozo de codigo que lo hagas, no es necesario que te declares las 18 variables, para eso pasale el contenido de las 18 columnas del datatable.
Para el correcto funcionamiento, y que otros usuarios se puedan beneficiar de la solucion de esta pregunta por favor marca las respuestas que te hayan ayudado como "Respuesta".
Si la respuesta te ha sido util Votala.
Mi Blog: Jtorrecilla
Enlace a Faq de Winforms en Ingles Muy bueno -
miércoles, 17 de marzo de 2010 20:18Es que eso quiero ahora, utilizarlas, lo que quiero es sacar el total, subtotal,dto,etc con cada variable y eso no cacho como hacerlo pero estoy buscando informacion, si ustedes tienen informacion o alguna pagina donde expliquen les pediria ayuda por favor.
-
miércoles, 17 de marzo de 2010 20:25si es asi como seria, me puede explicar por favor
-
miércoles, 17 de marzo de 2010 20:25ModeradorHola Benjamin te diria que cierres este que ya lo tienes encarrilado, y abras uno nuevo si quieres y vemos lo del tema de las variables y formas mas o menos correctas de hacerlo.
Para el correcto funcionamiento, y que otros usuarios se puedan beneficiar de la solucion de esta pregunta por favor marca las respuestas que te hayan ayudado como "Respuesta".
Si la respuesta te ha sido util Votala.
Mi Blog: Jtorrecilla
Enlace a Faq de Winforms en Ingles Muy bueno -
miércoles, 17 de marzo de 2010 20:26Moderadorhola
imagino porque como he seguido los post del tema que estos subtotales y totales los queires calcular para poder pasarselo al reporte
el tema es que vuelvo a remarcar, estas tomando el camino equivocado, estos calculos los hace directo el Crystal solito, le pasas los datos le indicas directo en el reporte la funcion de suma y solo agrupa, pero esto lo ahces en el diseñador de crystal
o sea no los calculas tu desde fuera y el apsas el valor el reporte, es el reporte una vez que tiene los datos el que realiza estas agrupaciones y calculos de totales
de este link
Crystal Reports Para Visual Studio.net Visual Basic.net Eidos
ve a la pagina 54, alli exsplica esto de totales y subtotales que losa rmas en crystal directamente, no necesitas complicarte tanto
saludos
Leandro Tuttini
Blog
Buenos Aires
Argentina -
miércoles, 17 de marzo de 2010 21:43genialo gracias ya abri otro post
-
miércoles, 17 de marzo de 2010 21:47leandro en la pagina que me acabas de colocar me sale este error
Error:
There was an error converting this document.
puedes revizar el link por favor. -
viernes, 19 de marzo de 2010 16:17
Aqui recorri el dataset y guarde en variables los valores que me extrajo la consulta del procedimiento almacenado, Gracias por sus ayudas.
private void FrmReportes_Load(object sender, EventArgs e)
{
try
{ RegistroFacturasVenta2();
using (SqlConnection conn = new SqlConnection(conexion))
{
conn.Open();SqlCommand cmd = new SqlCommand("SFAC_DetalleFactura", conn);
cmd.CommandType = CommandType.StoredProcedure;//Parametros de Entrada para el Sp
SqlParameter par_Correlativo = new SqlParameter("@fad_correlativo", SqlDbType.Int);
par_Correlativo.Value = this.ParCorrelativo;
cmd.Parameters.Add(par_Correlativo);//Parametreos de Salida
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
conn.Close();CrystalDecisions.CrystalReports.Engine.TextObject textObj0;
CrystalDecisions.CrystalReports.Engine.TextObject textObj1;
CrystalDecisions.CrystalReports.Engine.TextObject textObj2;
CrystalDecisions.CrystalReports.Engine.TextObject textObj3;
CrystalDecisions.CrystalReports.Engine.TextObject textObj4;
CrystalDecisions.CrystalReports.Engine.TextObject textObj5;
CrystalDecisions.CrystalReports.Engine.TextObject textObj6;
CrystalDecisions.CrystalReports.Engine.TextObject textObj7;
CrystalDecisions.CrystalReports.Engine.TextObject textObj8;
CrystalDecisions.CrystalReports.Engine.TextObject textObj9;
CrystalDecisions.CrystalReports.Engine.TextObject textObj10;
CrystalDecisions.CrystalReports.Engine.TextObject textObj11;
CrystalDecisions.CrystalReports.Engine.TextObject textObj12;
CrystalDecisions.CrystalReports.Engine.TextObject textObj13;
CrystalDecisions.CrystalReports.Engine.TextObject textObj14;
CrystalDecisions.CrystalReports.Engine.TextObject textObj15;
CrystalDecisions.CrystalReports.Engine.TextObject textObj16;
CrystalDecisions.CrystalReports.Engine.TextObject textObj17;
CrystalDecisions.CrystalReports.Engine.ReportDocument CrystalD = new ReportDocument();
CrystalD.Load(@"C:\Desarrollo\Facturador Final3\Facturador Final3\CrystalPinesRecarga.rpt");
crystalReportViewer1.ReportSource = CrystalD;
DataTable dt = ds.Tables[0];textObj0 = CrystalD.ReportDefinition.ReportObjects["Text1Encabezado"] as TextObject;
textObj1 = CrystalD.ReportDefinition.ReportObjects["Text2Encabezado"] as TextObject;
textObj2 = CrystalD.ReportDefinition.ReportObjects["Text3Encabezado"] as TextObject;
textObj3 = CrystalD.ReportDefinition.ReportObjects["Text4Encabezado"] as TextObject;
textObj4 = CrystalD.ReportDefinition.ReportObjects["Text5Encabezado"] as TextObject;
textObj5 = CrystalD.ReportDefinition.ReportObjects["Text6Encabezado"] as TextObject;
textObj6 = CrystalD.ReportDefinition.ReportObjects["Text7Encabezado"] as TextObject;
textObj7 = CrystalD.ReportDefinition.ReportObjects["Text8Encabezado"] as TextObject;
textObj8 = CrystalD.ReportDefinition.ReportObjects["Text9Encabezado"] as TextObject;
textObj9 = CrystalD.ReportDefinition.ReportObjects["Text1Detalle"] as TextObject;
textObj10 = CrystalD.ReportDefinition.ReportObjects["Text2Detalle"] as TextObject;
textObj11 = CrystalD.ReportDefinition.ReportObjects["Text3Detalle"] as TextObject;
textObj12 = CrystalD.ReportDefinition.ReportObjects["Text4Detalle"] as TextObject;
textObj13 = CrystalD.ReportDefinition.ReportObjects["Text5Detalle"] as TextObject;
textObj14 = CrystalD.ReportDefinition.ReportObjects["Text6Detalle"] as TextObject;
textObj15 = CrystalD.ReportDefinition.ReportObjects["Text7Detalle"] as TextObject;
textObj16 = CrystalD.ReportDefinition.ReportObjects["Text8Detalle"] as TextObject;
textObj17 = CrystalD.ReportDefinition.ReportObjects["Text9Detalle"] as TextObject;//DataTable dt = ds.Tables[0];
textObj0.Text= dt.Rows[0][0].ToString();
textObj1.Text = dt.Rows[0][1].ToString();
textObj2.Text = dt.Rows[0][2].ToString();
textObj3.Text = dt.Rows[0][3].ToString();
textObj4.Text = dt.Rows[0][4].ToString();
textObj5.Text = dt.Rows[0][5].ToString();
textObj6.Text = dt.Rows[0][6].ToString();
textObj7.Text = dt.Rows[0][7].ToString();
textObj8.Text = dt.Rows[0][8].ToString();
textObj9.Text = dt.Rows[0][9].ToString();
textObj10.Text = dt.Rows[0][10].ToString() + " " + dt.Rows[0][12].ToString() + " " + dt.Rows[0][14].ToString() + " " + dt.Rows[0][11].ToString() + " " + dt.Rows[0][15].ToString() + " " + dt.Rows[0][13].ToString();
//textObj11.Text = dt.Rows[0][11].ToString();
//textObj12.Text = dt.Rows[0][12].ToString();
//textObj13.Text = dt.Rows[0][13].ToString();
//textObj14.Text = dt.Rows[0][14].ToString();
//textObj15.Text = dt.Rows[0][15].ToString();
//textObj16.Text = dt.Rows[0][16].ToString();
//textObj17.Text = dt.Rows[0][17].ToString();crystalReportViewer1.RefreshReport();
conn.Close();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
}- Marcado como respuesta Aprendis24 viernes, 19 de marzo de 2010 16:17

