Solved

Setting Combo Box Defaults in vb Express

Posted on 2014-02-03
3
225 Views
Last Modified: 2014-02-06
I have a combobox linked to an SQL table, see attached code

'Read SQL data source in combobox
        cmd = New SqlCommand("SELECT * FROM tbl_ProductStandards", con)
        If con.State = ConnectionState.Closed Then con.Open()
        Dim sdr As SqlDataReader = cmd.ExecuteReader()
        While sdr.Read = True
            cboProductCode.Items.Add(sdr.Item("ProductCode"))
        End While
        sdr.Close()

But i would like to make an automatic selection in the combo box on form open if the combo box is blank

I have tried a variety of things including .selecteditem and although the code does not error, nothing vible ever appears in the combobox.

All suggestions very welcome.
0
Comment
Question by:SweetingA
3 Comments
 
LVL 17

Accepted Solution

by:
Kent Dyer earned 500 total points
Comment Utility
What you are looking for is the selected attribute..

<option value="audi" selected>Audi</option>

Open in new window

You will want to make this the default position if you will.
0
 
LVL 40

Expert Comment

by:Jacques Bourgeois (James Burger)
Comment Utility
cmd = New SqlCommand("SELECT * FROM tbl_ProductStandards", con)
        If con.State = ConnectionState.Closed Then con.Open()
        Dim sdr As SqlDataReader = cmd.ExecuteReader()
If srd.HasRows then
       While sdr.Read = True
            cboProductCode.Items.Add(sdr.Item("ProductCode"))
        End While
Else
     cboProductCode.Items.Add("Sorry, no product to show")
End If
       sdr.Close()
0
 

Author Comment

by:SweetingA
Comment Utility
Hello KentDyer,

I have tried various forms of using selected property but none work (no error just no visble selection in combo box field)

Could you please list the exact code
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
MS SQL Backup 24 70
Converting C# Objects into JSON file 7 36
sql server query? 6 26
Copy Database Wizard Error 3 20
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

744 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

19 Experts available now in Live!

Get 1:1 Help Now