标题:帮看看 问题出在哪了啊~求高手
只看楼主
viskin
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2014-11-22
 问题点数:0 回复次数:0 
帮看看 问题出在哪了啊~求高手
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)
        {

        }
    }
}
搜索更多相关主题的帖子: public 
2014-11-22 15:15



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-439013-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.094039 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved