.net 返回ID并插入(conn.Execute)

.net 返回ID并插入(conn.Execute),.net,sql-server,sqlconnection,.net,Sql Server,Sqlconnection,我正在使用以下命令插入新值: var message = conn.Execute("INSERT INTO [Message] (SenderId, Text, Date) values (@passeiDiretoUserId, @text, @date) SELECT SCOPE_IDENTITY()", new { @id, @text = send.Text, @date }); 查询工作正常,但我需要刚刚创建的值的ID。 谢谢 您可能正在寻找 执行查

我正在使用以下命令插入新值:

var message = conn.Execute("INSERT INTO [Message] (SenderId, Text, Date) values (@passeiDiretoUserId, @text, @date) SELECT SCOPE_IDENTITY()",
                new { @id, @text = send.Text, @date });
查询工作正常,但我需要刚刚创建的值的ID。
谢谢

您可能正在寻找

执行查询,并返回查询中第一行的第一列 查询返回的结果集。添加了其他列或行 忽略


查看
.ExecuteScalar
返回单个选定值