繁体   English   中英

在devexpress winforms中,如何从数据源将数据导入电子表格?

[英]In devexpress winforms, how can I import data into spreadsheet from a datasource?

下面是我的代码。 基本上,我只想从数据表及其原始列和行将数据输出到电子表格中。

public Spreadsheet()
    {
        InitializeComponent();

        Worksheet worksheet = spreadsheetControl1.Document.Worksheets[0];

        string connectionString = null;
        SqlConnection conn;
        connectionString = "Server=localhost\\SQLEXPRESS;Integrated security=SSPI;database=jms";
        SqlDataAdapter sda = new SqlDataAdapter("Select * from students", connectionString);

        conn = new SqlConnection(connectionString);
        DataTable dt5 = new DataTable("Students");

        worksheet.Import(dt5, true, 1, 1);


    }

我知道这很旧,但是您尚未用任何数据填充DataTable

您的代码应如下所示:

DataTable dt5 = new DataTable("Students");

//this actually executes the SQL and populates the DataTable
sda.Fill(dt5);

worksheet.Import(dt5, true, 1, 1);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM