|
-
Jan 12th, 2003, 11:30 PM
#1
Thread Starter
New Member
problem with combobox
using mircosoft visual basic .net on smart application device,plaform is pocket pc..
i tried using ' ComboBox2.Items.Insert(0, "-- Choose --") ' to make it as default,but it jjuz display my 1st record of my database..anyone idea why??
Here's my code..
Dim dsn As String
Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'determine which server and database to use
dsn = "server = 198.0.0.91; uid=sa; pwd=; database=Boxoffice"
Dim myConnection As SqlConnection = New SqlConnection()
myConnection.ConnectionString = dsn
Dim da As SqlDataAdapter = New SqlDataAdapter("Select * from Book", myConnection)
' create a new dataset
Dim ds As DataSet = New DataSet()
' fill dataset
da.Fill(ds, "Book")
' Attach DataSet to ComboBox2
ComboBox2.DataSource = ds.Tables(0)
ComboBox2.DisplayMember = "Date"
ComboBox2.Items.Insert(0, "-- Choose --")
End Sub
-
Jan 13th, 2003, 02:40 AM
#2
Registered User
Doesn't work that way unfortunately, either you load your combobox yourself or you use a datasource, if the latter it uses the records in the dataset no matter what.
-
Jan 13th, 2003, 06:44 AM
#3
Fanatic Member
Kryton
Include the "-- Choose --" in the SELECT statement using a union.
VB Code:
Dim da As SqlDataAdapter = New SqlDataAdapter("SELECT '-- Choose --' As date " _
& " UNION Select Date from Book", myConnection)
' create a new dataset
Dim ds As DataSet = New DataSet()
' fill dataset
da.Fill(ds, "Book")
' Attach DataSet to ComboBox2
ComboBox2.DataSource = ds.Tables(0)
ComboBox2.DisplayMember = "Date"
The select statement will expose a dataset with "-- Choose --" as the first item. Hope this works.
Using VB.NET 2003/.NET 1.1/C# 2.0
http://del.icio.us/rajoo
Blow your mind, smoke gunpowder
Ashes to ashes, dust to dust
If God won't have you, the devil will. - Author unknown
Don't follow me, I'm lost too ...
-
Jan 13th, 2003, 10:49 PM
#4
Thread Starter
New Member
thanks...but i've decided to load combobox myself ..ive tried all the code ,kept getting the same error whenever i add "ComboBox2.Items.Insert(0, "-- Choose --") " or
ComboBox2.Items.Add(0, "-- Choose --")
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|