我在表适配器中有一个insert
语句,但它一直返回1,而不是新插入的行的id。为什么呢?
Dim TA As New pTableAdapters.householdsTableAdapter
lblResult.Text = TA.Insert(New Guid("32dd20eb-1691-457b-9ff5-fc41d687e578"), Trim(Title), 0, "add", "addr2", _
"4544", "london", "ld", 0, "", Date.Now)
表适配器中的insert语句:
INSERT INTO households (userid, title, side, address, address2, zipcode, city, state, country, notes, createdate) VALUES (@userid,@title,@side,@address,@address2,@zipcode,@city,@state,@country,@notes,@createdate);SELECT CAST(scope_identity() AS int)
答案 0 :(得分:1)
从以下链接:http://blogs.msdn.com/b/smartclientdata/archive/2005/10/31/returnidentityvaluequery.aspx
...还有最后一个重要部分:在DataSet Designer中选择新查询,并将ExecuteMode属性从NonQuery更改为Scalar。 ...
NonQuery将返回受影响的行数(因此您总是得到1),而Scalar模式返回所选的值本身。