Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie databinding to dropdownlist question 1

Status
Not open for further replies.

RebLazer

Programmer
Jun 7, 2002
438
US
When I run this code:

Private Sub submit_org_nm_btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles submit_org_nm_btn.Click
'org_nm_selection = org_nm_tb.Text

Dim strSql As String
Dim strConn As String = ConfigurationSettings.AppSettings("ConnectstrW")
Dim conn As New SQLConnection(strConn)
strSql = "select org_nm from grant_info where org_nm like '" + org_nm_tb.Text + "%' "
Dim cmd As New SqlCommand(strSql, conn)
conn.Open()
candidate_orgs.datasource = cmd.ExecuteReader()
candidate_orgs.databind()
conn.Close()
End Sub


I get this error:
An invalid data source is being used for candidate_orgs. A valid data source must implement either IListSource or IEnumerable.


candidate_orgs is a (properly declared) dropdownlist.

What is wrong with this?

Thanks!
Lazer
 
Try using this:

Dim strSql As String
Dim strConn As String = ConfigurationSettings.AppSettings("ConnectstrW")
Dim conn As New SQLConnection(strConn)
strSql = "select org_nm from grant_info where org_nm like '" + org_nm_tb.Text + "%' "
Dim da As New SqlDataAdaptor(strSql, conn)
Dim dt as new DataTable
conn.Open()
da.Fill(dt)
candidate_orgs.datasource = dt
candidate_orgs.datavaluefield = "org_nm"
candidate_orgs.datatextfield = "org_nm"
candidate_orgs.databind()
conn.Close()

Hope this helps
NetAngel
 
NetAngel,

Thanks for your help - but I'm still getting exactly the same error:
An invalid data source is being used for candidate_orgs. A valid data source must implement either IListSource or IEnumerable.

on line:
candidate_orgs.DataBind()

I've run the SQL command on its own - it is fine.

Any ideas?
Thanks!
Lazer
 
NetAngel,

I'm embarrassed. I had the properties of candidate_orgs set to Datasource=Page....

Sorry/thanks,
Mr. Nooby Newbie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top