0

我有存储过程sp_ItemFilter,但问题是当我在文本框中插入数据时,我按btnButton发送数据,gridview中未显示的变为空,我该如何解决这个问题?使用的代码。

 Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Cmd = New SqlCommand("sp_codefilter", Cnn)
    Cmd.CommandType = CommandType.StoredProcedure
    With Cmd.Parameters
        .Add("@codigo", SqlDbType.VarChar, 6).Value = TextBox1.Text
        Cnn.Open()
        Try
            Dim dv As New DataView
            Da = New SqlDataAdapter(Cmd)
            Ds = New DataSet
            GridView1.DataSource = Ds.Tables()
            GridView1.DataBind()
        Catch ex As Exception
            MsgBox(ex.Message)
        Finally
            Cnn.Close()
        End Try
    End With
End Sub
End Class

感谢您阅读我的帖子

4

2 回答 2

1

尝试这个

Da = New SqlDataAdapter(Cmd)
Ds = New DataSet   //<---- this DataSet is empty and needs filling

Da.Fill(Ds);  //<------- You need to fill the DataSet here

GridView1.DataSource = Ds.Tables(0)
GridView1.DataBind()
于 2012-12-21T05:25:55.820 回答
0

您需要填充数据集,设置选择命令,并将特定表绑定到 GridView:

Dim Cmd As New SqlCommand("sp_codefilter", Cnn)
Cmd.CommandType = CommandType.StoredProcedure
With Cmd.Parameters
    .Add("@codigo", SqlDbType.VarChar, 6).Value = TextBox1.Text
End With

Cnn.Open()
Try
    Dim dv As New DataView
    Da = New SqlDataAdapter()
    Ds = New DataSet
    Da.SelectCommand = Cmd
    Da.Fill(ds, "MyTable");
    GridView1.DataSource = Ds.Tables("MyTable")
    GridView1.DataBind()
Catch ex As Exception
    MsgBox(ex.Message)
Finally
    Cnn.Close()
End Try
于 2012-12-21T05:30:38.507 回答