473,503 Members | 1,725 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Fill data toCombo box from dataset

Hello all,

how can i fill the data to combo box from dataset
please help me.

regards

lal
Nov 21 '05 #1
4 1428
Hi this bit of code shows you how to fill a combo with a sqldatareader (to
do it with a dataset is almost the same)and if you want you can also set it
to resize the dropdown part so that everything is fully displayed.

'Vul Combobox
Dim cmdReader As SqlCommand
Dim rdrReader As SqlDataReader
Dim cnComboBox As New SqlConnection("Connectionstring")
Dim blnDropDownMax As Boolean

cboCombo.Items.Clear()
cnComboBox.Open()
cmdReader = New SqlCommand("Your select statemen", cnComboBox)
rdrReader = cmdReader.ExecuteReader

Do While rdrReader.Read
If rdrReader("field") Is DBNull.Value Then
cboCombo.Items.Add("")
Else
cboCombo.Items.Add(directcast(rdrReader("field"),
String))
End If

Loop

cnComboBox.Close()

'toevoeging door Peter 16/12/2004 voor het automatisch
groter maken van de
'dropdown zodat deze even groot is als het grootste item

'Resize of the dropdownpart
If blnDropDownMax = True Then
Dim ds As Graphics = cboCombo.CreateGraphics
Dim x As Single = 0
Dim str As String
For Each str In cboCombo.Items
x = Math.Max(x, ds.MeasureString(str,
cboCombo.Font).Width)
Next
cboCombo.DropDownWidth = CInt(x) + 7
ds.Dispose()
End If

End If
End Sub

Be aware there's no error handling, you have to add that yourself. It's just
an example to get you started

hth Peter

--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning.

"K R Lal" <la**@yahoo.com> schreef in bericht
news:eY**************@TK2MSFTNGP14.phx.gbl...
Hello all,

how can i fill the data to combo box from dataset
please help me.

regards

lal

Nov 21 '05 #2

"K R Lal" <la**@yahoo.com> wrote in message
news:eY**************@TK2MSFTNGP14.phx.gbl...
Hello all,

how can i fill the data to combo box from dataset
please help me.

regards

lal

Try something like this, once your dataset has been populated:

With <your combo box>

.DataSource = <your dataset>

.DisplayMember = "field to display"

.ValueMember = "field to use as value member"

.SelectedIndex = -1 'to have the combo box appear empty when container
form first displays

End With
--
Peter [MVP Visual Developer]
Jack of all trades, master of none.
Nov 21 '05 #3
Dear Mr. Peter,
I tryied, but i can't understand what is the valumember, and I need one help
also. On data binding I want to change the "bindingcontext" on the combo
selected_index event.

please help me.

Lal

"Peter van der Goes" <p_**********@toadstool.u> wrote in message
news:#C**************@TK2MSFTNGP09.phx.gbl...

"K R Lal" <la**@yahoo.com> wrote in message
news:eY**************@TK2MSFTNGP14.phx.gbl...
Hello all,

how can i fill the data to combo box from dataset
please help me.

regards

lal

Try something like this, once your dataset has been populated:

With <your combo box>

.DataSource = <your dataset>

.DisplayMember = "field to display"

.ValueMember = "field to use as value member"

.SelectedIndex = -1 'to have the combo box appear empty when container
form first displays

End With
--
Peter [MVP Visual Developer]
Jack of all trades, master of none.

Nov 21 '05 #4

"K R Lal" <la**@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Dear Mr. Peter,
I tryied, but i can't understand what is the valumember, and I need one
help
also. On data binding I want to change the "bindingcontext" on the combo
selected_index event.

please help me.

Lal

Please read the following articles available in the MSDN help (.NET
Framework filter):
ComboBox class
ComboBox members
ListControl.ValueMember property

The articles include code examples and should clear up any questions.

--
Peter [MVP Visual Developer]
Jack of all trades, master of none.
Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1273
by: Dan | last post by:
I've created a web form which fills a DataGrid with a DataSet generated from the SqlDataAdapter.Fill method. The adapter's query takes about 30 seconds to complete when I run it in the SQL Server...
2
6058
by: Stanav | last post by:
Hello all, I'm developing a web application using VB.Net 2003 and Framework 1.1. This application queries an AS/400 database. I'm using the IBM OleDb provider that came with IBM Client Access for...
4
3737
by: Dave Edwards | last post by:
I understand that I can fill a datagrid with multiple queries, but I cannot figure out how to fill a dataset with the same query but run against multiple SQL servers, the query , table structure...
5
2284
by: moondaddy | last post by:
I have a website where cataloge pages are populated by calling a stored procedure on sql server. I use the sql data adapter's fill method to call this stored procedure and fill the dataset. about...
3
4604
by: Stanav | last post by:
Hello all, I'm developing a web application using VB.Net 2003 and Framework 1.1. This application queries an AS/400 database. I'm using the IBM OleDb provider that came with IBM Client Access for...
0
4526
by: mike1402 | last post by:
Hi ! I get the error below sometimes when retrieving a big amount of data using Datadapter.Fill(dataset,"table"). But when I send the command Fill again, there is no error. Is it a fault of...
2
4188
by: slinky | last post by:
I'm getting a error when I open my . aspx in my browser... line 34: da.Fill(ds, "Assets") Here's the error and my entire code for this .aspx.vb is below that ... I need some clues as to what is...
1
2571
by: Probi | last post by:
HI, I have a DropDownList populated from database I use the following code OracleDataAdapter ad2 = new OracleDataAdapter(cmd2, connection); DataSet ds2 = new DataSet(); ad2.Fill(ds2); ...
6
1561
by: obtrs | last post by:
i have a html form it and some php script to post it to database but every time i open page it show some error on the top but when i input data and send it it also send so how can i remove these...
0
7202
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7332
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6991
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7462
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1512
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
382
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.