Click here to Skip to main content
15,886,664 members
Please Sign up or sign in to vote.
1.33/5 (3 votes)
See more:
I am trying to populate a detailview based on textbox value. I get @txtname need to be declared. When I run the page.

VB
Protected Sub txtName_TextChanged(sender As Object, e As EventArgs) Handles txtName.TextChanged
     
      Dim con As SqlConnection = New SqlConnection("Data Source=HSE-SQL-01;Initial Catalog=Inspections;Integrated Security=True")
      Dim cmd As SqlCommand = New SqlCommand("SELECT DISTINCT * FROM [tbl_lat sewerconnection] WHERE ([LotAddress] = @txtName)", con)
      cmd.Parameters.AddWithValue("@Id", ID)
      'id is your value retrieved from textbox.
      Dim da As SqlDataAdapter = New SqlDataAdapter(cmd)
      Dim ds As DataSet = New DataSet()
      da.Fill(ds)
      'now bind the datasource with DeailsView Control.
      DetailsView1.DataSource = ds
      DetailsView1.DataBind()

vb.net code above



  End Sub



textbox declaration

XML
<asp:TextBox ID="txtName" runat="server"></asp:TextBox>



    <asp:AutoCompleteExtender ID="txtName_AutoCompleteExtender" runat="server"
        DelimiterCharacters="" Enabled="True" ServicePath=""
        TargetControlID="txtName" MinimumPrefixLength="2" CompletionInterval="1000"
        EnableCaching="false" FirstRowSelected="false" CompletionSetCount= "100" ServiceMethod="GetCompletionList"
        UseContextKey="True">
    </asp:AutoCompleteExtender>
Posted
Comments
[no name] 16-Jul-15 10:08am    
"@txtname need to be declared", that is because you have not created a parameter named @txtname.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900