Executenonquery返回值
我想在表上执行搜索以查看记录是否存在。我不想在之后执行插入或更新。我已经这样做了但不知何故我不能让这个工作。在我的asp.net页面上,我似乎无法获得任何返回值。错误是“输入字符串格式不正确”我确定它很明显,但我现在似乎无法看到它!
这是我的代码:
Dim con As New SqlConnection("connstring")
Dim cmd As New SqlCommand("checkname", con)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add(New SqlParameter("@d", SqlDbType.Int))
cmd.Parameters("@id").Value = TextBox1.Text
Dim para As New SqlParameter
para.Direction = ParameterDirection.ReturnValue
para.ParameterName = "returnvalue"
cmd.Parameters.Add(para)
con.Open()
cmd.ExecuteNonQuery()
Dim exists As Integer
exists = Convert.ToInt32(cmd.Parameters("returnvalue").Value)
If exists = 1 Then
Label1.Text = "You......"
ElseIf exists = 0 Then
Label1.Text = "You....."
End If
con.Close()
存储过程:
CREATE PROCEDURE checkname
-- Add the parameters for the stored procedure here
@id int
AS
--This means it exists, return it to ASP and tell us
-- SELECT 'already exists'
IF EXISTS(SELECT * FROM attendees WHERE id = @id)
BEGIN
RETURN 1
END
ELSE
BEGIN
RETURN 0
END
没有找到相关结果
已邀请:
4 个回复
搁手
(从技术上讲,你不需要“@”字符 在.NET中定义参数 码。)
惜堡沁戚
糕泰灌
返回受影响的行数。因此,您在存储过程中设置的返回值将被丢弃,并且不会被
方法返回。
蹄渭信妥扳