C# 学习笔记

1.C#调用外部exe

// 引用库
using System.Diagnostics;

/*************************************************************
 * 无参调用exe
 *************************************************************/
// 具体调用代码
Process m_Process = new Process();
m_Process.StartInfo.FileName = "exePath"; //exe所在的文件夹绝对路径
m_Process.Start();

/*************************************************************
 * 有参调用exe
 *************************************************************/
Process cmd = new Process(); 
cmd.StartInfo.FileName = @"exePath"; //exe所在的文件夹绝对路径
cmd.StartInfo.CreateNoWindow = false;// 显示命令行窗口
cmd.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
string param1 = "456", param2 = "789";
cmd.StartInfo.Arguments = param1+" "+param2;
cmd.Start();

参照链接

C#调用外部exe(2021.4.15)_jing_zhong的博客-优快云博客_c# 启动外部exeC#调用外部exe方式 2021.4.9调用C++封装好的exe调用Java封装好的exe调用java源码调用Python封装好的exe调用Python源码调用MATLAB封装好的exe测试调用C++封装好的exestring exefile = "d:\\chktool\\checktool.exe"; if (File.Exists(exefile)) { Process process = new Process(); ProcessStartInfhttps://blog.youkuaiyun.com/jing_zhong/article/details/115552400

2.调用*.mdb文件(System.Data.OleDb)

2.1.调用*.mdb环境

a. 要使用【Microsoft Access 数据库引擎可再发行程序包】32位。

 下载地址:Download Microsoft Access 2010 数据库引擎可再发行程序包 from Official Microsoft Download Centerbb

b.测试和打包时使用下x86环境运行

c.在NuGet中引入包"System.Data.OleDb"

2.2调用代码

// 引用包
using System.Data.OleDb;

//实现代码
private void bt_mdb_oledb_Click(object sender, EventArgs e)
{
    OleDbConnection conn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source="+数据库路径+";Jet OLEDB:Database Password="+ 数据库密码);
    conn.Open();
    OleDbCommand cmd = conn.CreateCommand();
    cmd.CommandText = "select * from " + 表名; // 查询语句
    OleDbDataReader dr = cmd.ExecuteReader(); // 执行查询语句
    DataTable dt = new DataTable();
    if (dr.HasRows) // 判断是否查询出结果
    {
       // 遍历取值
       for (int i = 0; i < dr.FieldCount; i++)
       {
           dt.Columns.Add(dr.GetName(i));
       }
       dt.Rows.Clear();
     }
     // 关闭数据库(上面代码的最好写个try-catch,然后把这块放finally里面)
     cmd.Dispose();
     conn.Close();
 }



//方法一**速度中等
OleDbDataReader reader = command.ExecuteReader();
while (reader.Read())
{
    var t1 = reader[0]; 
}

//方法二**速度最慢
OleDbDataReader reader = command.ExecuteReader();
while (reader.Read())
{
    var t1 = reader["字段名"]; 
}

//方法三**速度最快
OleDbDataReader reader = command.ExecuteReader();
while (reader.Read())
{
    var t1 = reader.GetValue(0); 
}

OleDbDataReader快速数据读取方式 - Hxxxxxxyyyyyy - 博客园

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值