本帖最后由 nmcfab 于 2015-1-20 23:43 编辑
[C#] 纯文本查看 复制代码 private void button2_Click(object sender, EventArgs e)
{
//根据指定的列数,从da表里取出该列的不重复值到临时表
string conString = this.txtFileName.Text;
string strSource = @"Provider =Microsoft.ACE.OLEDB.12.0;" + "data source=" + conString + ";Extended Properties='Excel 8.0; HDR=NO; IMEX=1'";
OleDbConnection conn = new OleDbConnection(strSource);
var myCell = "F" + this.textBox1.Text;
string sqlString = @"Select " + myCell + " from[Sheet1$]";
OleDbDataAdapter adapter = new OleDbDataAdapter(sqlString, conn);
DataSet da = new DataSet();
adapter.Fill(da);
DataView myView = da.Tables[0].DefaultView;
DataTable myTable = myView.ToTable(true, myCell); //其中ToTable()的第一个参数为是否DISTINCT
this.dataGridView2.DataSource = myTable;
} 解决了,mark下
|