ODBC:应用 ODBC 连接时插入/更新无法按预期工作

问题描述 投票:0回答:0

我试图让后端方法调用工作,它连接到数据库并执行表中的记录。该方法调用完美运行,不会抛出任何错误,但同时不会更新表中的任何记录。

注:

  1. SELECT 查询按预期返回数据。
  2. 是插入和更新没有按预期工作。

这是我的方法片段,它连接数据库并尝试使用

ExecuteNonQuery()
方法执行更新查询。

    public void Update(Insights ins)
        {
            string DbConnection = ConnectionSetting.ConnectDatabricks();
            string query = @"UPDATE Archery SET Insight = '?', Title = '?' WHERE Sub_Topic = '?'";
            
            try
            {
                using (OdbcConnection connection = new OdbcConnection(DbConnection))
                {
                    connection.Open();
                    OdbcCommand command = new OdbcCommand(query, connection);
                    command.CommandText = query;

                    command.Parameters.Add("@insight", OdbcType.NVarChar).Value = ins.Insight;
                    command.Parameters.Add("@title", OdbcType.NVarChar).Value = ins.Title;
                    command.Parameters.Add("@subject", OdbcType.NVarChar).Value = ins.Subject;
                    command.ExecuteNonQuery();
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
c# odbc
© www.soinside.com 2019 - 2024. All rights reserved.