1

我正在努力让查询通过网络表单运行和显示结果。它使用参数将值传递到存储过程中,但是尽管设置了 @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

任何帮助表示赞赏。

4

1 回答 1

2

尝试在 proc 中更改参数声明:

@status nvarchar(200) --For example

现有声明会将您的输入修剪为第一个字符:

例如下面的代码:

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

exec paramtest 'foobar'

只选f

于 2012-06-29T22:50:50.137 回答