In actual development, we often encounter data conversion needs. We can transfer the data in Excel to SQL, or import the data in the database table into Excel.CodeAs follows:
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 GemBox. ExcelLite;
Using System. Data. SqlClient;
Using System. Data. OleDb;
Using System. Collections;
Using System. IO;
Namespace Encryption
{
Public partial class ExcelDemo: Form
{
Private static string _ filePath = string. Empty;
Public ExcelDemo ()
{
InitializeComponent ();
BindUser ();
}
/// <Summary>
/// Bind data
/// </Summary>
Private void BindUser ()
{
String SQL = "select * from Users ";
DataTable dt = DbHelperSQL. QueryTb (SQL );
DataGridView1.DataSource = dt;
}
/// <Summary>
/// Import the data in the Users table to Excel
/// </Summary>
Private void btnExcelin_Click (object sender, EventArgs e)
{
ExcelFile excelFile = new ExcelFile ();
ExcelWorksheet sheet = excelFile. Worksheets. Add ("Users ");
Int columns = maid. Count;
Int rows = maid. Count;