【问题标题】:How to retrieve row ID on ADO.NET DataAdapter.InsertCommand如何在 ADO.NET DataAdapter.InsertCommand 上检索行 ID
【发布时间】:2012-09-26 08:35:52
【问题描述】:

我将 ADO.NET 与 MySQL 一起使用。

为了插入数据,我使用了 DataAdapter (MySqlDataAdapter):

MySqlCommand insertCommand = new MySqlCommand(@"INSERT INTO Investments (InvestmentType)
                                                            VALUES (@InvestmentType); SET @ID=@@IDENTITY;"
                                                         , (MySqlConnection)Connection);
insertCommand.Parameters.Add("@InvestmentType", MySqlDbType.VarChar, 255, "InvestmentType");
DbParameter parameter = insertCommand.Parameters.Add("@ID", MySqlDbType.UInt32, 0, "ID");
parameter.Direction = ParameterDirection.Output;
((MySqlDataAdapter)InvestmentsAdapter).InsertCommand = insertCommand;
((MySqlDataAdapter)EmptyInvestmentsAdapter).InsertCommand = insertCommand;

我希望它填充行“ID”列,因为@ID 参数应该是一个 OUT 参数,但它会引发一个异常,因为 MySQL 有问题,因为它的计算结果为“SET NULL=@@IDENTITY;”。

有什么想法吗?

这灵感来自于 Tim Cook 的“Microsoft ADO.NET 4”,它似乎在使用 SQL Server 而我使用 MySQL。我找不到有关 MySQL 适配器输出参数的任何文档。

【问题讨论】:

    标签: mysql ado.net identity dataadapter out-parameters


    【解决方案1】:

    这篇文章对我很有用:

    MSDN Tutorial

    问候,

    彼得

    【讨论】:

      猜你喜欢
      • 2012-05-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-03
      • 2011-02-11
      相关资源
      最近更新 更多