OLEDBConnection:将字节 [] 插入 blob 不保存更改
OLEDBConnection: Insert byte[] into blob doesn't save change
我正在尝试使用 OLEDBconnection 更新记录。我想要更新的数据(字节数组)将作为 blob 存储在 oracle 中。然而,当行到达 ExecuteNonQuery
时,什么都没有改变
我试过的:
我认为查询本身有问题。所以我尝试了以下方法:
1:使用其他查询进行测试:
@"UPDATE dcmnts
SET TestCol = ?
where BUSNSS_ID = ?";
至此运行,TestCol
更新成功。它是一个 varchar 列
2:确保绑定在查询中出现的顺序与问号相同,也没有用
3:在末尾放一个Console.WriteLine
,它提示:“1 row with 12345678 updated”,所以确实更新了,但是当我查看Oracle Developer时,Summary_SPOD
列仍然为空
public void SaveSPODLetter(byte[] Letter, string TrackingNumber )
{
string query = @"UPDATE dcmnts
SET SUMMARY_SPOD = ?
where BUSNSS_ID = ?";
OleDbCommand command = null;
string ConnString = ConfigurationManager.ConnectionStrings["My_db"].ToString();
using (OleDbConnection connection = new OleDbConnection(BaseEncryptor.DecryptString(ConnString)))
{
try
{
if (connection.State != ConnectionState.Open)
connection.Open();
command = new OleDbCommand(query, connection);
command.Parameters.Add(new OleDbParameter("SUMMARY_SPOD", Letter));
command.Parameters.Add(new OleDbParameter("BUSNSS_ID", TrackingNumber));
int rowUpdate = command.ExecuteNonQuery();
Console.WriteLine($"{rowUpdate} row with {TrackingNumber} updated");
}
finally
{
if (command != null) { command.Dispose(); command = null; }
}
}
}
我不确定为什么它仍然显示错误,是否与 Letter
是字节数组这一事实有关?
我不确定这是否算作解决方案,但它似乎与 OleDB 有关。
我一直不明白为什么,所以我切换到 Oracle.DataAccess.Client
并相应地更改了所有功能。之后就成功了。
public void SaveSPODLetter(byte[] Letter, string TrackingNumber )
{
string query = @"UPDATE dcmnts
SET SUMMARY_SPOD = :Summary_SPOD
where BUSNSS_ID = :BUSNSS_ID";
OracleCommand command = null;
string ConnString = ConfigurationManager.ConnectionStrings["My_db"].ToString();
using (OracleConnection connection = new OracleConnection(BaseEncryptor.DecryptString(ConnString)))
{
try
{
if (connection.State != ConnectionState.Open)
connection.Open();
command = new OracleCommand(query, connection);
command.Parameters.Add(new OracleParameter("Summary_SPOD", Letter));
command.Parameters.Add(new OracleParameter("BUSNSS_ID", TrackingNumber));
command.ExecuteNonQuery();
//Console.WriteLine($"{rowUpdate} row with {TrackingNumber} updated");
}
finally
{
if (command != null) { command.Dispose(); command = null; }
}
}
}
我正在尝试使用 OLEDBconnection 更新记录。我想要更新的数据(字节数组)将作为 blob 存储在 oracle 中。然而,当行到达 ExecuteNonQuery
时,什么都没有改变
我试过的:
我认为查询本身有问题。所以我尝试了以下方法:
1:使用其他查询进行测试:
@"UPDATE dcmnts
SET TestCol = ?
where BUSNSS_ID = ?";
至此运行,TestCol
更新成功。它是一个 varchar 列
2:确保绑定在查询中出现的顺序与问号相同,也没有用
3:在末尾放一个Console.WriteLine
,它提示:“1 row with 12345678 updated”,所以确实更新了,但是当我查看Oracle Developer时,Summary_SPOD
列仍然为空
public void SaveSPODLetter(byte[] Letter, string TrackingNumber )
{
string query = @"UPDATE dcmnts
SET SUMMARY_SPOD = ?
where BUSNSS_ID = ?";
OleDbCommand command = null;
string ConnString = ConfigurationManager.ConnectionStrings["My_db"].ToString();
using (OleDbConnection connection = new OleDbConnection(BaseEncryptor.DecryptString(ConnString)))
{
try
{
if (connection.State != ConnectionState.Open)
connection.Open();
command = new OleDbCommand(query, connection);
command.Parameters.Add(new OleDbParameter("SUMMARY_SPOD", Letter));
command.Parameters.Add(new OleDbParameter("BUSNSS_ID", TrackingNumber));
int rowUpdate = command.ExecuteNonQuery();
Console.WriteLine($"{rowUpdate} row with {TrackingNumber} updated");
}
finally
{
if (command != null) { command.Dispose(); command = null; }
}
}
}
我不确定为什么它仍然显示错误,是否与 Letter
是字节数组这一事实有关?
我不确定这是否算作解决方案,但它似乎与 OleDB 有关。
我一直不明白为什么,所以我切换到 Oracle.DataAccess.Client
并相应地更改了所有功能。之后就成功了。
public void SaveSPODLetter(byte[] Letter, string TrackingNumber )
{
string query = @"UPDATE dcmnts
SET SUMMARY_SPOD = :Summary_SPOD
where BUSNSS_ID = :BUSNSS_ID";
OracleCommand command = null;
string ConnString = ConfigurationManager.ConnectionStrings["My_db"].ToString();
using (OracleConnection connection = new OracleConnection(BaseEncryptor.DecryptString(ConnString)))
{
try
{
if (connection.State != ConnectionState.Open)
connection.Open();
command = new OracleCommand(query, connection);
command.Parameters.Add(new OracleParameter("Summary_SPOD", Letter));
command.Parameters.Add(new OracleParameter("BUSNSS_ID", TrackingNumber));
command.ExecuteNonQuery();
//Console.WriteLine($"{rowUpdate} row with {TrackingNumber} updated");
}
finally
{
if (command != null) { command.Dispose(); command = null; }
}
}
}