asp.net/vb.net - ddl not creating an error, but not pulling data

My code to pupulate a dropdown list on button click runs fine...however, its still not populating the DDL and its not throwing an error in the code...

in runtime all I get is :
System.Data.DataRowView
in the dropdownlist...


I ran the query in SQL by itself, and it ran fine...so the issue has to be the sql connection or the .net code itself...
Dim var_search_box As String

        var_search_box = TextBox1.Text
        Session("var_search_box") = TextBox1.Text

        Session("search_ddl") = True
        Try

            Dim MyDropDown As DropDownList
          
            MyDropDown = DropDownList1

            Session("var_search_box") = TextBox1.Text
            Dim var_trim_search As String
            var_trim_search = Session("var_search_box")
            var_trim_search = LTrim(RTrim(var_trim_search))



            Using sqlConn As New SqlConnection
               
                sqlConnection = "Data Source=shoesdata;Initial Catalog=shoedb;Persist Security Info=True;User ID=abccomp;Password=abcomp"
                sqlConn.ConnectionString = sqlConnection
               

                Dim SQLstring As String = " SELECT top 5 (name) FROM  shoetype WHERE name like '%" & var_trim_search & "%'"


                Dim TblAdaptar As New SqlDataAdapter(SQLstring, sqlConn)
                Dim Tbl As New DataSet

                Tbl.Clear()
                Try

                    TblAdaptar.Fill(Tbl)
                    MyDropDown.DataSource = Tbl
                    MyDropDown.DataBind()

                Catch ex As Exception
                End Try

            End Using

        Catch ex As Exception

        End Try

Open in new window

LVL 10
GlobaLevelAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Paul MacDonaldConnect With a Mentor Director, Information SystemsCommented:
              Try
                    TblAdaptar.Fill(Tbl)
                   MyDropDown.DataTextField = ???
                    MyDropDown.DataValueField = ???
                    MyDropDown.DataSource = Tbl.Tables(0)

                    MyDropDown.DataBind()
                Catch ex As Exception
0
 
binaryevoCommented:
you need to specify a datatextfield and a datavaluefiedl for your dropdown, otherwise it wont know what to use thus the reson your getting the System.Data.DataRowView in the dropdown.
0
 
binaryevoCommented:
Dropdownlist1.DataTextField= "SomeTextFieldInTable1";
Dropdownlist1.DataValueField="SomeValueFieldInTable1";
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
GlobaLevelAuthor Commented:

Dropdownlist1.DataTextField= "SomeTextFieldInTable1";
Dropdownlist1.DataValueField="SomeValueFieldInTable1";

Would this be the name of the column? or a piece of data in the column?
0
 
GlobaLevelAuthor Commented:
not sure how to use this..
Dropdownlist1.DataTextField= "SomeTextFieldInTable1";
Dropdownlist1.DataValueField="SomeValueFieldInTable1";


the name of the column is 'NAME'
0
 
GlobaLevelAuthor Commented:
o I think like this:

 <asp:DropDownList ID="DropDownList1" runat="server"       DataTextField="name"
            DataValueField="name">
         </asp:DropDownList>


but what do I do if I my sql statement contains multiple fields that I want to have in a DDL

"Select col1,col2,col3. from table1 where x = ...."

and the DDL would look like this, with columns lined up:

[col1] [col2] [col3] [col4]
[col1] [col2] [col3] [col4]
[col1] [col2] [col3] [col4]
[col1] [col2] [col3] [col4]
0
 
Paul MacDonaldDirector, Information SystemsCommented:
"Would this be the name of the column? or a piece of data in the column?"
Name of the column.
0
 
Paul MacDonaldDirector, Information SystemsCommented:
             ...
             Try
                    TblAdaptar.Fill(Tbl)
                    MyDropDown.DataTextField = "Name"
                    MyDropDown.DataValueField = ???
                    MyDropDown.DataSource = Tbl.Tables(0)
                    MyDropDown.DataBind()
                Catch ex As Exception

              ...
 
0
 
CodeCruiserCommented:
>but what do I do if I my sql statement contains multiple fields that I want to have in a DDL

You can do a concatenation

Select col1 + ' ' + col2 + ' ' + col3 ...
0
 
Paul MacDonaldDirector, Information SystemsCommented:
I think the OP was worried each column in his query would show up in the DDL, which is not the case by default.
0
All Courses

From novice to tech pro — start learning today.