我一直在寻找互联网的深度,我发现的所有解决方案都没有解决这个问题。ASP.NET - 无法找到存储过程
我使用Visual Web Developer 2010 Express与SQL Server 2008,使用VB。
我想执行一个存储过程,将一些数据从文本框控件插入到数据库中,如果该ID不存在,它将同时插入文本框中给出的id和当前日期(time_scanned_in),if该ID已经存在,它会将当前日期时间插入[time_scanned_out]
列中,如果数据库中的所有3个字段都已满,则将返回@message = 1
。
这里是SQL存储过程:
ALTER PROCEDURE dbo.InsertDateTime
@barcode_id nchar(20),
@message char(1) = 0 Output
AS
BEGIN
if not exists(select * from tblWork where barcode_id = @barcode_id)
begin
INSERT INTO [tblWork] ([barcode_id], [time_scanned]) VALUES (@barcode_id, GetDate())
end
else if exists(select * from tblWork where barcode_id = @barcode_id AND time_scanned_out IS NOT NULL)
begin
SET @message=1
end
else if exists(select * from tblWork where barcode_id = @barcode_id AND time_scanned_out IS NULL)
begin
UPDATE [tblWork] SET [time_scanned_out] = GetDate() WHERE [barcode_id] = @barcode_id
end
RETURN @message
end
如果我执行这个(用鼠标右键点击该SP),它完美的作品,并在各个领域已经排满返回值。
但是,当通过vb代码执行时,不能找到这样的过程,在标题中给出错误。
这里是VB代码:
Dim opconn As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
Dim sqlConnection1 As New SqlConnection(opconn)
Dim cmd As New SqlCommand
Dim returnValue As Object
cmd.CommandText = "InsertDateTime"
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = sqlConnection1
sqlConnection1.Open()
With cmd.Parameters.Add(New SqlParameter("@barcode_id", TextBox.Text))
End With
With cmd.Parameters.Add(New SqlParameter("@message", SqlDbType.Char, 1, Label3.Text))
End With
returnValue = cmd.ExecuteScalar()
sqlConnection1.Close()
注意,我没有做过的返回部分的代码呢,会做,一旦我得到它的定位SP。
尝试列出gridview中每个数据库的sys.objects.name的所有对象,它列出了除我想要的存储过程之外的所有内容。
这是为什么,有什么想法?将不胜感激,花了几个小时试图找到解决方案。 如果有人需要更多的代码或信息,请随时提问。
尝试'cmd.CommandText =“dbo.InsertDateTime”' – 2012-08-07 14:51:58
有很多不同的前缀包括一个的试了很多次,试过我的用户名称和一切,完全相同的错误。 – Charlie 2012-08-07 14:53:30
你确定你连接的数据库有这个proc吗? – Shyju 2012-08-07 14:54:00