• oleDbCommand访问Excel


    oleDbCommand访问Excel:
    _oleCmdSelect = new OleDbCommand("SELECT * FROM [Sheet1$A2:A5]", _oleConn);
    objValue = _oleCmdSelect.ExecuteScalar();

    using System;
    using System.Collections.Generic;
    using System.Text;
     
    namespace ConsoleApplication1
    {
        class Program
        {
            private static string _vsPath = @"Provider=Microsoft.ACE.OLEDB.12.0;
                   Data Source=D:\work\0228\test\Solution2\ReadExcel07\Members.xlsx;Extended Properties=""Excel 12.0;HDR=YES;""";
     
            static void Main(string[] args)
            {
                System.Data.OleDb.OleDbConnection vOleDbConnection = new System.Data.OleDb.OleDbConnection(_vsPath);
                vOleDbConnection.Open();
                System.Data.OleDb.OleDbDataAdapter oleDbDataAdapter=new System.Data.OleDb.OleDbDataAdapter();
                oleDbDataAdapter.SelectCommand = new System.Data.OleDb.OleDbCommand("SELECT * FROM [Sheet1$A2:A5]",vOleDbConnection);
                System.Data.DataTable dataTable=new System.Data.DataTable();
                oleDbDataAdapter.FillSchema(dataTable,System.Data.SchemaType.Source);
                oleDbDataAdapter.Fill(dataTable);
                oleDbDataAdapter.Dispose();
     
                Console.WriteLine("Over");
                Console.Read();
            }
        }
    }
    using System;
    using System.Collections.Generic;
    using System.Text;
     
    namespace ConsoleApplication1
    {
        class Program
        {
            private static string _vsPath = @"Provider=Microsoft.ACE.OLEDB.12.0;
                   Data Source=D:\work\0228\test\Solution2\ReadExcel07\Members.xlsx;Extended Properties=""Excel 12.0;HDR=YES;""";
     
            static void Main(string[] args)
            {
                System.Data.OleDb.OleDbConnection vOleDbConnection = new System.Data.OleDb.OleDbConnection(_vsPath);
                vOleDbConnection.Open();
                System.Data.OleDb.OleDbDataAdapter oleDbDataAdapter = new System.Data.OleDb.OleDbDataAdapter();
                oleDbDataAdapter.SelectCommand = new System.Data.OleDb.OleDbCommand("SELECT * FROM [Sheet1$]", vOleDbConnection);
                System.Data.DataTable dataTable = new System.Data.DataTable();
                oleDbDataAdapter.FillSchema(dataTable, System.Data.SchemaType.Source);
                oleDbDataAdapter.Fill(dataTable);
                oleDbDataAdapter.Dispose();
     
                System.Data.OleDb.OleDbCommand oleDbCommand = new System.Data.OleDb.OleDbCommand("INSERT INTO [Sheet1$] ([Full Name],[ID Number]) values ('F1','F2')", vOleDbConnection);
                oleDbCommand.ExecuteNonQuery();
     
                Console.WriteLine("Over");
                Console.Read();
            }
        }
    }

    http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbdataadapter.insertcommand.aspx

  • 相关阅读:
    Python连接MySQL
    Python监控文件夹 && 发送邮件
    CentOS安装Redis
    weak_ptr
    libevent(六)http server
    libevent(五)使用例子
    laravel查询数据库获取结果如何判断是否为空?
    centos7 php-fpm 开机启动
    centos7 防火墙
    Laravel
  • 原文地址:https://www.cnblogs.com/hongjiumu/p/2940303.html
Copyright © 2020-2023  润新知