datagridview到CrystalReports [英] datagridview to a CrystalReports
本文介绍了datagridview到CrystalReports的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在此代码中有问题,我想将数据从DataGridView传输到Crystal Report
但有错误有人可以帮助我吗?
这是我的代码:
I have a problem in this code i want to Transfer the datas from DataGridView To Crystal Report
but have an error can anybody help me ???
this is my code :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
DB db = new DB();
DataSet ds;
private void button1_Click(object sender, EventArgs e)
{
ds = db.ExecuteDataset(CommandType.StoredProcedure, "sp_user_list", "T", new SqlParameter[]
{
new SqlParameter("@sex",comboBox1.Text)
});
dataGridView1.DataSource = ds.Tables["T"];
dataGridView1.Columns[0].HeaderText = "کد کاربر";
dataGridView1.Columns[1].HeaderText = "نام";
dataGridView1.Columns[2].HeaderText = "نام خانوادگی";
dataGridView1.Columns[3].HeaderText = "جنسیت";
dataGridView1.Columns[4].HeaderText = "تلفن";
dataGridView1.Columns[5].HeaderText = "آدرس";
}
private void button2_Click(object sender, EventArgs e)
{
crystalReportViewer1.Enabled = true;
DataTable dt = new DataTable();
dt = dataGridView1.DataSource as DataTable;
ds.Tables.Add(dt);
//error is in this line . it say the invenrep does not exist.
invenrep.SetDataSource(ds);
crystalReportViewer1.ReportSource = invenrep;//this line too
}
}
}
如何解决这个问题.
how resolve this problem . what format must be define for " invenrep"???
推荐答案
给出了错误,指出invenrep不存在,因为您无法在代码中声明.
因此,请声明invenrepand,而不要尝试运行代码.
或
我认为您的代码不完整.
it is giving error that invenrep does not exist because you can''t declare that in your code.
so please declare invenrepand than try to run your code.
or
i think your code is incomplete.
这篇关于datagridview到CrystalReports的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文