Solved

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

Posted on 2010-11-20
4
307 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

919 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

15 Experts available now in Live!

Get 1:1 Help Now