private void button1_Click(object sender, EventArgs e)
{
// string word = textBox1.Text;
// string word1;
//指定Excel文件的路径
string file_name = @"D:\log\log1.xls";
//拼装一个连接字符串
// string strConn = "Provider=Microsoft.Jet.Oledb.4.0;Data Source=" + file_name + ";Extended Properties='Excel 8.0;HDR=YES;IMEX=1;'";
string strConn = "Provider=Microsoft.ACE.OLEDB.12.0;" + "data source=" + file_name + ";Extended Properties='Excel 8.0;HDR=Yes;IMEX=1'";
//声明一个连接对象
OleDbConnection conn = new OleDbConnection(strConn);
//将查询结果放入数据适配器中
OleDbDataAdapter adp = new OleDbDataAdapter("select * from [Sheet1$] where cellid='" + textBox1.Text.ToString() + "'", conn);
//声明一个DataSet
DataSet ds = new DataSet();
//将查询出的记录集从数据适配器中放到DataSet中
adp.Fill(ds);
//数据绑定
DataTable table = ds.Tables[0];
// dataGridView1.DataSource = ds.Tables[0];
DataRow[] rows = table.Select();
string num;
num = rows[0].ItemArray[1].ToString();//这里抛异常
conn.Close();
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.FileName = "G:\\"+num+".jpg";
process.StartInfo.Arguments = "rundll32.exe C://WINDOWS//system32//shimgvw.dll";
process.StartInfo.UseShellExecute = true;
process.Start();
}
求助大佬
相似问题