【发布时间】: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