[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 677
  • Last Modified:

Drop Down List Displays system.data.datarowview

I'm trying to populate a drop down list with one column of a sql view but instead I'm getting system.data.datarowview on every row. I've read about the column names etc. being incorrect etc and have checked that. I've also tried using dbo.vDepts and vDepts for the view name but it made no difference.

Thanks in advance!!
Imports System
Imports System.Collections
Imports System.Data
Imports System.Net.Mail
Imports System.Net
Imports System.IO
Imports System.Security.Permissions
Imports System.Text
Imports System.DirectoryServices
 
Partial Public Class _Default
    Inherits System.Web.UI.Page
    Dim strUser As String
    Dim strDate As Date
    Dim DS As System.Data.DataSet
 
 Private Sub FillDropdown()
        Dim sConn As Data.SqlClient.SqlConnection
        Dim sComm As Data.SqlClient.SqlCommand
        Dim sAdapt As Data.SqlClient.SqlDataAdapter
 
        sConn = New Data.SqlClient.SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("MyConnection2").ConnectionString)
        sComm = New Data.SqlClient.SqlCommand("Select Depts from dbo.vDepts", sConn)
        sAdapt = New Data.SqlClient.SqlDataAdapter(sComm)
        sConn.Open()
 
        DS = New DataSet
        sAdapt.Fill(DS)
        sComm.ExecuteReader()
        DropDownList10.DataSource = DS
        DropDownList10.DataBind()
        sConn.Close()
 
    End Sub

Open in new window

0
JB4375
Asked:
JB4375
  • 2
1 Solution
 
oobaylyCommented:
You should set the DataTextField property for the drop down list to the column you wish to display:
DropDownList10.DataTextField = "Depts "

Open in new window

0
 
JB4375Author Commented:
It works!!
Thanks Oobayly!!
0
 
JB4375Author Commented:
Right on the money the first time!! Thanks!!
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now