首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带有asp.net和SqlDataSource控件的SqlDataSource输出参数

带有asp.net和SqlDataSource控件的SqlDataSource输出参数
EN

Stack Overflow用户
提问于 2011-07-19 20:40:32
回答 1查看 666关注 0票数 0

我正在将我的应用程序从MSSQL切换到MYSQL。当我使用MSSQL时,我通过

代码语言:javascript
复制
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

代码语言:javascript
复制
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();"

现在当我尝试

代码语言:javascript
复制
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();"

我知道错误:

您的SQL语法出现了错误;请检查与MySQL服务器版本对应的手册,以便在第1行使用接近'0 = LAST_INSERT_ID()‘的正确语法。

当我试着:

代码语言:javascript
复制
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();"

我知道错误:

未知系统变量“impoundId”

最终,我只是试图获得最后一个自动增量值,但在其他应用程序中,我还计划将代码的其他部分切换到MYSQL,这些部分依赖于输出参数。我还没有探索如何使用存储过程,但此时我想让它以类似于我如何使用MSSQL的方式工作。

提前谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-07-21 05:05:56

最后,我崩溃了,决定使用存储过程。这是做任何事情的最好方法,并使代码更加简洁。对于遇到同样问题的人,我的建议是不要浪费时间让它正常工作,只需要使用一个存储过程。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6753837

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档