方法一:(未使用存储过程)
string
sqlc
=
"
insert into sendmailbox (username) values (@Username) SELECT @@IDENTITY as id
"
;SqlCommand myCommand
=
new
SqlCommand(sqlc, myConnection);myCommand.Parameters.Add(
new
SqlParameter(
"
@Username
"
, SqlDbType.VarChar));myCommand.Parameters[
"
@Username
"
].Value
=
un;myCommand.Connection.Open();
int
Id
=
Convert.ToInt32(myCommand.ExecuteScalar());myCommand1.Connection.Close();
方法二:(用存储过程来实现)
Create
procedure
insSendmail(
@UserName
varchar
(
20
))
as
Declare
@ID
int
begin
transaction
Insert
into
sendmailbox(username)
values
(
@UserName
)
Select
@ID
=
@@IDENTITY
commit
transaction
return
@ID
转载请注明原文地址: https://ibbs.8miu.com/read-50386.html