all groups > dotnet academic > may 2005 >
You're in the

dotnet academic

group:

Listbox Population of DB data...


Listbox Population of DB data... jess.peralta NO[at]SPAM intel.com
5/30/2005 4:46:04 PM
dotnet academic:
Hi,

I have tried (I believe) everthing I know about databinding... I'm trying
to populate a data from a database to a listbox using VB.NET tru following
script but not able too... could you tell me what I missed?

Dim strSQL As String
Dim myconnection As SqlConnection
Dim mycommand As SqlDataAdapter

strSQL = "SELECT * FROM table WHERE primaryID = '" &
TextBox.Text & "'"
Dim conn As String = ConfigurationSettings.AppSettings("[Server
Connection string Key]")
myconnection = New SqlConnection(conn)
mycommand = New SqlDataAdapter(strSQL, myconnection)

Dim ds As New DataSet
Dim dummy As DataRowView

mycommand.Fill(ds, "FullName")
dummy = ds.Tables("FullName").DefaultView(0)
LB.DataSource = dummy("FullName")
LB.DataBind()



RE: Listbox Population of DB data... Ashish
7/10/2005 5:11:02 PM
hi there


try this


SQL String
Dim cmdString As String = "Select customers from ma order by pid "

Try
'Open connection
myConnection.Open()

'open command object
Dim cmbperiod As New SqlCommand(cmdString, myConnection)

Dim drperiod As SqlDataReader
drperiod = cmbperiod.ExecuteReader()
Do While drperiod.Read()
periodComboBox.Items.Add(drperiod.Item(0))
periodComboBox.SelectedIndex = 0

Loop
myConnection.Close()

'Add the error handling code here.
'Display error message, if any.

Catch ae As SqlException
MessageBox.Show(ae.Message)
End Try


--
Just next to technology


[quoted text, click to view]
RE: Listbox Population of DB data... Prasad (MCAD)
9/14/2005 1:16:03 AM
Hi,
this one i think suits better with your code.
After assigning datasource to listbox speicfy the DisplayMember &
ValueMember property of the listbox.

lst.DisplayMember="Name"
lst.ValueMember="Id"

this will solve you prolem.

Reg,
Prasad

[quoted text, click to view]
AddThis Social Bookmark Button