2012-12-21 78 views
0

我已存儲過程sp_ItemFilter,但問題是,當我插入文本框數據,我按btnButton發送數據,在GridView未顯示爲空,我怎麼能解決這個問題? 使用的代碼。文本框搜索的GridView與存儲過程ASP.NET

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 

感謝閱讀我的文章

回答

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() 
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