0

我将 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 适配器输出参数的任何文档。

4

1 回答 1

1

这篇文章对我来说非常有用:

MSDN 教程

问候,

彼得

于 2013-08-01T21:43:11.447 回答