如何将字节数组插入数据库中的blob单元?

xghobddn  于 2021-07-26  发布在  Java
关注(0)|答案(2)|浏览(447)

我使用此代码编辑数据库中的数据。当像int或string这样的数据时,一切都正常,但我不明白如何将字节数组插入到具有blob数据类型的单元格中。3天已经被风暴谷歌,youtube,但我找不到解决办法。

OdbcTransaction transaction = null;
                OdbcCommand command = new OdbcCommand();

                transaction = connection.BeginTransaction();

                command.Connection = connection;
                command.Transaction = transaction;

                command.CommandText = "UPDATE tb_vs SET te_file=" + bytes + " WHERE te_comp LIKE '" + ParStr + "'";
                //command = new OdbcCommand("UPDATE tb_vs SET te_file=" + bytes + " WHERE te_comp LIKE '" + ParStr + "'", connection);
                //command.Parameters.Add("@byte", OdbcType.Blob).Value = bytes;

                command.ExecuteReader();
                transaction.Commit();
6za6bjd0

6za6bjd01#

这个代码提示我

using (var transaction = connection.BeginTransaction())
using (var command = new OdbcCommand())

command.Connection = connection;
command.Transaction = transaction;

command.CommandText =
    "UPDATE tb_vs SET te_file = ? WHERE te_comp LIKE ?";

command.Parameters.Add("@p1", OdbcType.Binary).Value = bytes;
command.Parameters.Add("@p2", OdbcType.NVarChar).Value = ParStr;

int rowsAffected = command.ExecuteNonQuery();
transaction.Commit();

但它给出了一个新的错误:
system.data.odbc.odbcexception:“错误[hy000][microsoft][odbc transbase driver][transbase]常规错误。transbase exec错误报告:参数0的类型不匹配(got binchar(*),需要blob)

cgvd09ve

cgvd09ve2#

您需要将数组转换为字符串。因为oracle不识别c#数组

相关问题