?
Solved

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

Posted on 2010-11-20
4
Medium Priority
?
315 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 400 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 1600 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

752 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