private void button1_click()
{
try
{
if(this.dataSet1.Tables.Count>0)
{
this.dataSet1.Tables[0].Rows.Clear();
}
string filename ="";
DialogResult result =openFileDialog1.ShowDialog();
if( result == DialogResult.OK )
{
filename=openFileDialog1.FileName;
lbl_path.Text=filename;
string strCon = " Provider = Microsoft.Jet.OLEDB.4.0 ; " + "Data Source =" + filename + ";Extended Properties=Excel 8.0";
OleDbConnection myConn = new OleDbConnection(strCon);
myConn.open();
string strCom = "Select * FROM [Sheet1$] ";
OleDbDataAdapter myCommand = new OleDbDataAdapter(strCom,myConn);
myCommand.Fill(dataSet1,"[Sheet1$]");
myConn.Close();
mygrid.SetDataBinding(dataSet1,"[Sheet1$]");
this.BT_ScreenOut.Enabled = true;
this.btn_Insert.Enabled = false;
}
}
catch(System.Exception e)
{
MessageBox.Show(e.Message);
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。