首页 > 编程语言 >C# 连接EXCEL 文本框保存输入信息

C# 连接EXCEL 文本框保存输入信息

时间:2023-04-30 13:12:01浏览次数:49  
标签:Settings C# Text EXCEL System 文本框 Default using Properties

部分代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.OleDb;

namespace WindowsFormsApp8
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string Path = textBox1.Text.Trim();
            string sql = textBox2.Text.Trim();
            //string connStr = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + Path + ";" + "Extended Properties=Excel 8.0;";
            string connStr = "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + Path + ";" + "Extended Properties=Excel 8.0;";
            OleDbConnection conn = new OleDbConnection(connStr);
            conn.Open();
            OleDbDataAdapter myCommand = null;
            DataSet ds = null;
            myCommand = new OleDbDataAdapter(sql, connStr);
            ds = new DataSet();
            myCommand.Fill(ds, "table1");

            dataGridView1.DataSource = ds.Tables[0];
            conn.Dispose();
        }

     

        private void Form1_Load(object sender, EventArgs e)
        {
            textBox1.Text = Properties.Settings.Default.defaultPath;
            textBox2.Text = Properties.Settings.Default.defaultSQL;
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            Properties.Settings.Default.defaultPath = textBox1.Text.Trim();
            Properties.Settings.Default.defaultSQL = textBox2.Text.Trim();
            Properties.Settings.Default.Save();
        }
    }
}

 

标签:Settings,C#,Text,EXCEL,System,文本框,Default,using,Properties
From: https://www.cnblogs.com/sound-of-wind-rain/p/17365158.html

相关文章

  • ASP.NET Core – Data Protection & Azure Storage + Azure Key Vault
    前言以前就写过很多篇了Asp.netcore学习笔记(Dataprotection)Asp.netcore学习笔记Secret和DataProtectAzurekey-vault&StorageAccount第2篇Azure入门系列(第五篇AzureStorage)这篇作为最新最完整的版本呗. 参考Docs– GetstartedwiththeDa......
  • Python中django的ORM和SQLalchemy简单对比(一)
    1.ORM对象关系映射(英语:ObjectRelationMapping,简称ORM,或O/RM,或O/Rmapping),是一种程序技术,用于实现面向对象编程语言里不同类型系统的数据之间的转换。从效果上说,它其实是创建了一个可在编程语言里使用的“虚拟对象数据库”。一般的ORM包括以下四部分:一个对持久类对象......
  • koa-cors 源码及基本原理解析
    cors: 跨域资源共享(Cross-OriginResourceSharing)是一种机制,用来允许不同源服务器上的指定资源可以被特定的Web应用访问。在koa项目中使用cors中间件:eg:1varkoa=require('koa');2varroute=require('koa-route');3varcors=require('koa-cors');4varapp......
  • CSC246/446机器学习
    CSC246/446MachineLearningHomework5:ClusteringObjectiveYouaregiventwokindsofdataset.DatasetsA,B,C,andZwerecreatedbytheinstructorbysamplingfromfourdifferentGaussianmixtures,withdifferentnumbersofmixturecomponents.Yourfi......
  • COMP30024人工智能
    ProjectPartBPlayingtheGameCOMP30024ArtificialIntelligenceApril20231OverviewInthissecondpartoftheproject,wewillplaythefulltwo-playerversionofInfexion.Beforeyoureadthisspecificationyoushouldre-readthe‘RulesfortheGame......
  • IDEA报错:Internal error :java.lang.illegalAccessErrorjiang
    IDEA报错:Internalerror:java.lang.illegalAccessErrorjiang报错Internalerror:java.lang.illegalAccessErrorjiang原因及解决方法今天在IDEA运行一个新项目时发生了这个报错,原因是该项目使用较新的JDK17版本,而我一直使用的IDEA2019.3.5不支持JDK17,将IDEA版本更换为2021.2.......
  • c#-单链表
    namespaceMyLink;publicclassMyLinkedList{privateint_size{get;set;}publicclassMyTreeNode{publicintval{get;set;}publicMyTreeNodenext{get;set;}publicMyTreeNode(intval){this.val=val;......
  • ABC300 Editorial
    哭了,还是写不了Ex的题解,因为不会A-N-choicequestion题意给定\(a,b\)和序列\(\{c_n\}\),求\(a+b\)在\(c\)中的下标。分析直接记录一下\(pos_{c_i}=i\)就薄纱了。codeconstintmaxn(2e5+500);intn,a,p[maxn];intmain(){ n=read(),a=read()+r......
  • [ERR] collect2: fatal error: cannot find 'ld'
    今天在orinnano上希望g++使用lld代替ld时候,在如下命令时候抛出了如标题的错误>>g++-fuse-ld=llda.cccollect2:fatalerror:cannotfind'ld'compilationterminated.因为最开始配置llvm-15环境时候我有将lld-15软连接为lld,所以使用lld是可以正确执行的,但是看起来g++并......
  • C++之forward
    不管是T&&、左值引用、右值引用,std::forward都会按照原来的类型完美转发。forward主要解决引用函数参数为右值时,传进来之后有了变量名就变成了左值。 #include<QCoreApplication>#include<memory>#include<iostream>usingnamespacestd; template<typenameT>void......