-1
我需要從datagridview傳輸數據到reportviewer。我的代碼:datagridview到reportviewer C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.Reporting.WinForms;
namespace test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//dataGridView1.AutoGenerateColumns = false;
dataGridView1.Columns.Add("test");
dataGridView1.Columns.Add("One");
dataGridView1.Columns.Add("two");
dataGridView1.Columns.Add("three");
dataGridView1.Columns.Add("four");
dataGridView1.Columns.Add("five");
dataGridView1.Columns.Add("six");
dataGridView1.Rows.Add("test", "test ", "1", "2", "3", "4");
dataGridView1.Rows.Add(980, 10, 70, 20, 50);
dataGridView1.Rows.Add(860, 20, 50, 60, 35);
dataGridView1.Rows.Add(950, 80, 35, 30, 40);
dataGridView1.Rows.Add(800, 40, 90, 30, 25);
dataGridView1.Rows.Add(900, 20, 45, 30, 60);
dataGridView1.Rows.Add(300, 20, 20, 20, 20);
dataGridView1.Rows.Add("check" , 50, 80, 50, 70);
}
}
這些引用並沒有幫助: How to Pass data table from DataGridView ro ReportViewer
Show data from datagridview to reportviewer C# 如何顯示從DataGridView數據的ReportViewer C#?
您可以使用'DataTable'作爲'DataGridView'的'DataSource'。然後使用相同的'DataTable'創建一個報告,並將其設置爲報告的'DataSource'。 –
我也試過,報告爲空。 DataTable table1 = new DataTable(); dataGridView1.DataSource = table1; (「test」); ... DataSet set = new DataSet(); set.DataSetName =「datasetname」; set.Tables.Add(table1); – player
你是'DataGridView'在上面的例子中不使用'DataSource'。您正在向控件直接添加行。使用'DataTable'。 –