Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 中继器控制搜索按钮_Asp.net_Vb.net - Fatal编程技术网

Asp.net 中继器控制搜索按钮

Asp.net 中继器控制搜索按钮,asp.net,vb.net,Asp.net,Vb.net,我的repeater控件正在显示加载的数据库字段 我在中继器控制外有一个搜索按钮。按下按钮时,我希望中继器仅显示中继器中的搜索结果。我该怎么做 这是显示全部的代码。在搜索时,我不想在repeater中显示以下详细信息。只显示搜索结果 受保护的子转发器() Dim cmd作为新的SqlCommand(“从abc中选择*”,con) 端接头 下面是我在搜索按钮中添加的新代码 cmd = New SqlCommand cmd.Connection = con cmd.Co

我的repeater控件正在显示加载的数据库字段

我在中继器控制外有一个搜索按钮。按下按钮时,我希望中继器仅显示中继器中的搜索结果。我该怎么做

这是显示全部的代码。在搜索时,我不想在repeater中显示以下详细信息。只显示搜索结果

受保护的子转发器() Dim cmd作为新的SqlCommand(“从abc中选择*”,con)

端接头 下面是我在搜索按钮中添加的新代码

       cmd = New SqlCommand
    cmd.Connection = con

   cmd.CommandText = "select * from ABC where LicenseID = '" & TextBox16.Text & "'"
      drd = cmd.ExecuteReader
      If drd.HasRows = True Then
    drd.Read()

   End If

     Using con = New SqlConnection("Data Source=ABC-556012RT13\SQLEXPRESS;Initial      Catalog=KABC;Integrated Security=True")
    Using da = New SqlDataAdapter("select * from ABC where LicenseID = @LicenseID", con)
        da.SelectCommand.Parameters.AddWithValue("@LicenseID", TextBox16.Text)
Dim table = New DataTable
  da.Fill(table)
 Repeater1.DataSource = table
        Repeater1.DataBind()
    End Using
End Using       
使用sql参数来

除此之外,只需将查询结果用作中继器的数据源,例如,通过填充
数据表

Using con = New SqlConnection("connectionString")
    Using da = New SqlDataAdapter("select * from abc where LicenseID = @LicenseID", con)
        da.SelectCommand.Parameters.AddWithValue("@LicenseID", TextBox16.Text)
        Dim table = New DataTable
        da.Fill(table)
        repeater1.DataSource = table
        repeater1.DataBind()
    End Using
End Using

我还使用
using
-语句来确保所有非托管资源(如开放连接)即使出现错误也会被释放。

如果不希望数据库被劫持,请使用sql参数。不会显示错误,但所有许可证id都随搜索字段一起出现。如果我键入1,我只想在中继器中显示该许可证ID,但它正在显示all@user2797643:代码中的
SqlCommand
SqlDataReader
部分现在是多余的。此外,您还对我的代码进行了注释,我将
DataSource
设置为
DataTable
。为什么?当我尝试你的方法时,它也没有显示搜索结果。这就是为什么我评论了一个尝试过的方法。
Using con = New SqlConnection("connectionString")
    Using da = New SqlDataAdapter("select * from abc where LicenseID = @LicenseID", con)
        da.SelectCommand.Parameters.AddWithValue("@LicenseID", TextBox16.Text)
        Dim table = New DataTable
        da.Fill(table)
        repeater1.DataSource = table
        repeater1.DataBind()
    End Using
End Using