Solved

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

Posted on 2010-11-20
4
310 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

749 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