2011-07-19 5 views
0

アプリケーションをMSSQLからMYSQLに切り替える処理中です。asp.netとSqlDataSourceコントロールのMySQL出力パラメータ

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '0 = LAST_INSERT_ID()' at line 1

:私はMSSQLを使用していたとき、私は私が

InsertCommand="INSERT INTO LotManager_impounds (accountId, truckId, createdBy, driver, locationId, dateArrived, towedFrom, reasonForImpound, reasonForImpoundOther, impoundCity, impoundCounty, timeOfImpound, dateDeemedAbandoned, ticketNumber) VALUES (@accountId,@truckId,@createdBy,@driver,@locationId,@dateArrived,@towedFrom,@reasonForImpound,@reasonForImpoundOther,@impoundCity,@impoundCounty,@timeOfImpound,@dateDeemedAbandoned,@ticketNumber); SET @impoundId = LAST_INSERT_ID();" 

をしようとすると、今、私はエラーを取得

Private Sub dsImpoundInformation_Inserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceStatusEventArgs) Handles dsImpoundInformation.Inserted 
    _impoundId = e.Command.Parameters("impoundId").Value 
End Sub 

Private Sub dsImpoundInformation_Inserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceCommandEventArgs) Handles dsImpoundInformation.Inserting 
    Dim impoundIdparam As New SqlClient.SqlParameter() 
    impoundIdparam.ParameterName = "impoundId" 
    impoundIdparam.Direction = System.Data.ParameterDirection.Output 
    impoundIdparam.DbType = DbType.Int32 
    impoundIdparam.Value = 0 
    e.Command.Parameters.Add(impoundIdparam) 
End Sub 

InsertCommand="INSERT INTO LotManager_impounds (accountId, truckId, createdBy, driver, locationId, dateArrived, towedFrom, reasonForImpound, reasonForImpoundOther, impoundCity, impoundCounty, timeOfImpound, dateDeemedAbandoned, ticketNumber) VALUES (@accountId,@truckId,@createdBy,@driver,@locationId,@dateArrived,@towedFrom,@reasonForImpound,@reasonForImpoundOther,@impoundCity,@impoundCounty,@timeOfImpound,@dateDeemedAbandoned,@ticketNumber); SET @impoundId = SCOPE_IDENTITY();" 

を経て、最後の自動インクリメント値を取得し

と私が試したとき:

InsertCommand="INSERT INTO LotManager_impounds (accountId, truckId, createdBy, driver, locationId, dateArrived, towedFrom, reasonForImpound, reasonForImpoundOther, impoundCity, impoundCounty, timeOfImpound, dateDeemedAbandoned, ticketNumber) VALUES (@accountId,@truckId,@createdBy,@driver,@locationId,@dateArrived,@towedFrom,@reasonForImpound,@reasonForImpoundOther,@impoundCity,@impoundCounty,@timeOfImpound,@dateDeemedAbandoned,@ticketNumber); SET impoundId = LAST_INSERT_ID();" 

私はエラーを取得する:

Unknown system variable 'impoundId'

最終的に、私は最後の自動インクリメント値を取得しようとしているが、私はへの切り替えを計画し、他のアプリケーションで私のコードの他のセクションがあります出力パラメータに依存するMYSQL。私はまだストアドプロシージャを使用していませんが、現時点では、これをMSSQLでどのように使用したのと同様の方法で動作させたいと考えています。

ありがとうございます。

答えて

0

最後に、私は壊れて、ストアドプロシージャを使用することに決めました。これは何らかの方法で行う最善の方法であり、コードをもっときれいにします。この同じ問題に遭遇している人にとっては、私のアドバイスは時間を無駄にせずに、ストアドプロシージャを使用するだけです。

関連する問題