首先是界面设计,这个我就随便拉了三个控件 ,两个button,一个dataGridView,如图所示:
实现逻辑:用odbc将excel表格数据查出,存到 datatable, 然后把datatable数据填充到datagridview中
然后附上完整代码:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
DataTable dt = new DataTable();
//数据库连接字段
string connString = "server =192.168.1.222; uid = sa; pwd = *_*Wenz,a; database = test1";
SqlConnection conn;
private void button1_Click(object sender, EventArgs e)
{
System.Windows.Forms.OpenFileDialog fd = new OpenFileDialog();
if (fd.ShowDialog() == DialogResult.OK)
{
string fileName = fd.FileName;
bind(fileName);
}
}
priv