求高手 帮忙看看,问题出在哪了
using System;using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.OleDb;
using Tekla.Structures.Model;
using Tekla.Structures;
using Tekla.Structures.Model.UI;
namespace BEAM_1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog diolog = new OpenFileDialog();
diolog.Filter = "Excel 文件(*xls)|*xls";
diolog.FileName = "";
if (diolog.ShowDialog() == DialogResult.OK)
{
string PathString = diolog.FileName.Trim();
this.listView1.Items.Clear();
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source =" + PathString + ";" + "Extended Properties=;'Excel 8.0;HDR=NO;IMEX=1';";
String strExcel = "select*from[sheet1$]";
OleDbConnection conn = null;
try
{
conn = new OleDbConnection(strConn);
conn.Open();
OleDbCommand cmd = new OleDbCommand(strExcel, conn);
OleDbCommand reas = cmd.ExecuteReader();
while (reas.Read())
{
string CeLingDH = reas[0].ToString();
string strAssNum = reas[1].ToString();
string strParNum = reas[2].ToString();
string strSize = reas[3].ToString();
string strMaterial = reas[4].ToString();
string strGrade = reas[5].ToString();
ListViewItem lv = new ListViewItem(CeLingDH);
lv.SubItems.Add(strAssNum);
lv.SubItems.Add(strParNum);
lv.SubItems.Add(strSize);
lv.SubItems.Add(strMaterial);
lv.SubItems.Add(strGrade);
listView1.Items.Add(lv);
}
}
catch (OleDbException ex)
{
MessageBox.Show("打开错误!" + ex.Message);
}
finally
{
conn.Close();
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}