如何使用 OleDB 将文件任何文件附加到 sql 命令,以及如何从访问数据库中读取它

问题描述

这是我尝试将本地照片按地址添加到我的访问数据库的测试代码

测试表有两列int id,目标文件

  [Theory]
        [InlineData("test",@"D:\download\up.png")]
        public void Insertimage(string table,string address)
        {
            string query = sql_Queries.Insert(table,new List<object>() { 0,"@file" });
            //query = 'insert into test values(0,@file);'
            Assert.True(Access.Execute(query,address));
        }

这是访问执行代码,如果成功则返回真或假

       public static bool Execute(string command,string address)
    {
        FileInfo file = new FileInfo(address);
        try
        {
            ConnectionState(true);
            OleCommand = new OleDbCommand(command,Connection);
            OleCommand.Parameters.AddWithValue("@file",file);
            OleCommand.ExecuteReader();
        }
        catch (Exception err)
        {
            Error = err.Message;
            ConnectionState(false);
            return false;
        }
        ConnectionState(false);
        return true;
    }

给我一​​个错误 cannot perform that operation

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)