2012-06-29 33 views
1

我正努力通過Web表單運行並顯示結果。它使用一個參數將值傳遞給存儲過程,但儘管設置了@status值,但它看起來並沒有被sp拾取,因此也沒有返回結果。我的Vb相當有限,我懷疑這是問題所在。存儲過程不從網頁中獲取參數

繼承人的SQL:

ALTER proc [dbo].[get_status_times] 

@status nvarchar 
as 

select project_code, activity_code, project_date, project_time from 
timesheet where status = @status 

和VB

Sub detailsClicked(ByVal sender As Object, ByVal e As DataGridCommandEventArgs) Handles listweekstatus.ItemCommand 
    Dim wccolumn As TableCell = e.Item.Cells(0) 
    ' Dim timeColumn As TableCell = e.Item.Cells(1) 
    Dim statusColumn As TableCell = e.Item.Cells(2) 
    ' Dim buttonColumn As TableCell = e.Item.Cells(3) 


    Dim wccoltext As DateTime = wccolumn.Text 
    ' Dim timeColText As String = timeColumn.Text 
    Dim statusColText As String = statusColumn.Text 
    ' Dim buttonColText As String = buttonColumn.Text 

    Dim myConnection As New SqlConnection(ConfigurationManager.ConnectionStrings("chronosdb").ConnectionString) 

    Const strSQL As String = "get_status_times" 
    Dim myCommand As New SqlCommand(strSQL, myConnection) 


    myCommand.CommandType = CommandType.StoredProcedure 


    myCommand.Parameters.Add("@status", SqlDbType.NVarChar) 
    myCommand.Parameters("@status").Value = statusColText 
    myCommand.Parameters("@status").Direction = ParameterDirection.Input 

    'Set the datagrid's datasource to the datareader and databind 
    myConnection.Open() 
    weekdetails.DataSource = myCommand.ExecuteReader(CommandBehavior.CloseConnection) 
    weekdetails.DataBind() 


End Sub 

讚賞任何幫助。

回答

2

試着改變你的PROC您的參數聲明:

@status nvarchar(200) --For example 

現有的聲明將被你輸入微調的第一個字符:

例如下面的代碼:

create proc paramtest (@param nvarchar) 
as 
begin 
select @param 
end 
go 

exec paramtest 'foobar' 

只需選擇f

+1

+1 [當n未在數據區中指定時定義或變量聲明語句,默認長度爲1.](http://msdn.microsoft.com/zh-cn/library/ms186939.aspx) – Andomar

+0

什麼是你是Jon的明星。整理出來。一直以來我一直認爲VB是錯誤的,它是SP。非常感謝。 –

+0

@DaveHenderson:nps - 它通常是需要別人注意的小東西。樂意效勞。 –