Solved

What is the equivalent of the following code for fill a combobox in vb.net windows form.

Posted on 2010-11-20
4
306 Views
Last Modified: 2012-05-10
billreport.aspx.vb
Imports System.Data
Imports System.Data.SqlClient
Partial Class _Default
    Inherits System.Web.UI.Page
    Dim cn As SqlConnection
    Dim cmd As SqlCommand
    Dim s As String
    Dim dr As SqlDataReader
 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        cn = New SqlConnection("server=116-pc\sqLEXPRESS;Initial Catalog=hms;Integrated Security=True")
        If (Not IsPostBack) Then
            bindpid()
        End If
    End Sub
    Public Function bindpid()
        s = "Select distinct pid from labtest"
        cmd = New SqlCommand(s, cn)
        cn.Open()
        dr = cmd.ExecuteReader()
        ddlpid.DataTextField = "pid"
        ddlpid.DataValueField = "pid"
        ddlpid.DataSource = dr
        ddlpid.DataBind()
        Dim li As ListItem
        li = New ListItem
        li.Text = "--Select Patient Id--"
        li.Value = "0"
        ddlpid.Items.Insert(0, li)

        cn.Close()
    End Function
End Class
0
Comment
Question by:searchsanjaysharma
  • 2
4 Comments
 
LVL 12

Assisted Solution

by:Anuradha Goli
Anuradha Goli earned 100 total points
ID: 34181946
ComboBox1.DataSource = objDataTable
 ComboBox1.DisplayMember = "pid"
 ComboBox1.ValueMember = "pid"

Refer this link

http://www.java2s.com/Code/VB/Database-ADO.net/DatabaseDataBindingComboBox.htm
0
 

Author Comment

by:searchsanjaysharma
ID: 34182002
What is the equivalent of this
   Dim li As ListItem
        li = New ListItem
        li.Text = "--Select Patient Id--"
        li.Value = "0"
        ddlpid.Items.Insert(0, li)

0
 
LVL 35

Accepted Solution

by:
Miguel Oz earned 400 total points
ID: 34182122
The equivalent is:
    ddlpid.Items.Insert(0, "--Select Patient Id--")
0
 

Author Closing Comment

by:searchsanjaysharma
ID: 34213622
ok
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now