开发者

i have problem to get new inserted columnID using sql

开发者 https://www.devze.com 2023-01-03 11:44 出处:网络
I have an identity column defined as int in sql . I use SCPOE_IDENTITY () to get the new inserted column id.

I have an identity column defined as int in sql . I use SCPOE_IDENTITY () to get the new inserted column id.

this is sample of my code:

     Dim sql As开发者_Python百科 String = "insert into infoHotel (nameHotel, knownAs1, knownAs2, knownAs3, knownAs4, streetAddress) values (N" & _
                                       FormatSqlParam(hotel) & ",N" & _
                                       FormatSqlParam(KnownAs(0)) & ",N" & _
                                       FormatSqlParam(KnownAs(1)) & ",N" & _
                                       FormatSqlParam(KnownAs(2)) & ",N" & _
                                       FormatSqlParam(KnownAs(3)) & ",N" & _
                                       FormatSqlParam(StreetAddress) & _
                                       "SELECT CAST(scope_identity() AS int)")"

    Dim objCommand1 As New SqlCommand(sql, conn)

    Dim infoID As Integer = objCommand1.ExecuteScalar()

my problem here is, i cant get the infoID's value..is my code wrong?..some help plzz.. im using vb.net n sql


I think you are missing a bracket and the end of your SQL statement.

It should read

FormatSqlParam(StreetAddress) & ")" & _


I think you need to commit your changes to the database before you can query it...

0

精彩评论

暂无评论...
验证码 换一张
取 消