Solved

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

Posted on 2010-11-20
4
311 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 36

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

690 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