简体   繁体   中英

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

Below is my code. Basically I just want to output data into my spreadsheet from a datatable, with its original columns and rows.

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);


    }

I know this is old but you have not populated your DataTable with any data.

Your code should look like this:

DataTable dt5 = new DataTable("Students");

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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