PDA

View Full Version : سوال: گزارش گیری با Report Viewer با کد نویسی در Load فرم



mostafarastin239
سه شنبه 03 خرداد 1390, 13:43 عصر
سلام به همه،
من می خواهم بعد از اینکه اطلاعات فاکتور در سیستم ثبت شد شماره فاکتور را به قسمت مربوط به چاپ ارسال کنم و توسط لود فرم چاپ توسط ریپورت ویور اطلاعات همان فاکتور را چاپ کنم. کد زیر را نوشتم ولی جواب نمی دهد. shfa همان شماره فاکتور است که از فرم فاکتور به فرم پرینت ارسال می شود.

private void report_Load(object sender, EventArgs e)
{
try
{
SqlDataAdapter objdataadapter = new SqlDataAdapter();
DataSet dstmp = new DataSet();
DataTable dstmp1 = new DataTable();
objdataadapter.SelectCommand = new SqlCommand();
objdataadapter.SelectCommand.Connection = objconnection;
objdataadapter.SelectCommand.CommandText = "SELECT shomare_factor , code_kala , nam_kala , sathe_joz , tedad , sathe_kol" + " , fee_vahed , fee_kol , tedad_kala , mablaghe_kol , takhfif , pardakht FROM factor where shomare_factor = '" + shfa + "'";
objdataadapter.SelectCommand.CommandType = CommandType.Text;
objconnection.Open();
objdataadapter.Fill(dstmp, "factor");
objdataadapter.Fill(dstmp1);
ReportDataSource repds = new ReportDataSource("dstmp", dstmp.Tables["dstmp1"]);
reportViewer1.LocalReport.DataSources.Clear();
reportViewer1.LocalReport.DataSources.Add(repds);
reportViewer1.LocalReport.Refresh();
this.reportViewer1.RefreshReport();
objconnection.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}

با تشکر

bazardeh
سه شنبه 03 خرداد 1390, 14:00 عصر
یه نگاهی به این بنداز من از این استفاده می کنم


private void SAllReport_Load(object sender, EventArgs e)
{
try
{
SqlConnection con = new SqlConnection("Server=(local);database=School;integrated security=true;");
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
DataTable dt = new DataTable();
con.Open();
SqlCommand com = new SqlCommand();
com.Connection = con;
com.CommandText = "select * from student ";

da.SelectCommand = com;

da.Fill(dt);

ReportDocument rd = new ReportDocument();
rd.FileName = @".\CrystalStudent.rpt";
rd.SetDataSource(dt);

crystalReportViewer1.ReportSource = rd;


// crystalReportViewer1.ReportSource = @".\CrystalStudent.rpt";
}
catch (SqlException ex)
{
MessageBox.Show("" + ex.Message + " " + ex.Errors, "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}

mostafarastin239
سه شنبه 03 خرداد 1390, 16:00 عصر
یه نگاهی به این بنداز من از این استفاده می کنم


private void SAllReport_Load(object sender, EventArgs e)
{
try
{
SqlConnection con = new SqlConnection("Server=(local);database=School;integrated security=true;");
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
DataTable dt = new DataTable();
con.Open();
SqlCommand com = new SqlCommand();
com.Connection = con;
com.CommandText = "select * from student ";

da.SelectCommand = com;

da.Fill(dt);

ReportDocument rd = new ReportDocument();
rd.FileName = @".\CrystalStudent.rpt";
rd.SetDataSource(dt);

crystalReportViewer1.ReportSource = rd;


// crystalReportViewer1.ReportSource = @".\CrystalStudent.rpt";
}
catch (SqlException ex)
{
MessageBox.Show("" + ex.Message + " " + ex.Errors, "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}



سلام جواب نداد.




public partial class report : Form
{
SqlConnection objconnection = new SqlConnection("Data Source = .\\SQLEXPRESS ; AttachDbFilename
= |DataDirectory|\\Arman_Andish.mdf ; Integrated Security = True ; User Instance = True");
SqlCommand objcommand = new SqlCommand();
string shfa = "";
public report(string sh_factor)
{
InitializeComponent();
shfa = sh_factor;
}
private void report_Load(object sender, EventArgs e)
{
try
{
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
DataTable dt = new DataTable();
objconnection.Open();
objcommand.Connection = objconnection;
objcommand.CommandText = "SELECT shomare_factor , code_kala , nam_kala , sathe_joz , tedad ,
sathe_kol" + " , fee_vahed , fee_kol , tedad_kala , mablaghe_kol , takhfif , pardakht FROM factor
where shomare_factor = '" + shfa + "'";
MessageBox.Show("shfa : " + shfa);
da.SelectCommand = objcommand; da.Fill(dt);
ReportDataSource repds = new ReportDataSource("dt", ds.Tables["dt"]);
repds.Name = @".\Report1.rdlc";
repds.Value = dt;
this.reportViewer1.LocalReport.DataSources.Add(rep ds);
}
catch (SqlException ex)
{
MessageBox.Show("" + ex.Message + " " + ex.Errors
, "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}

mostafarastin239
دوشنبه 09 خرداد 1390, 17:14 عصر
سلام به همه،
کسی نبود جواب ما را بده؟؟؟
با تشکر