hi every one after connecting to an excel file I want to import the firts row into a combobox
in the connection function I added thhis
MyCommand = New System.Data.OleDb.OleDbDataAdapter("select * from[sheet1$]", MyConnection)
MyCommand.TableMappings.Add("Table", "Attendence")

DtSet = New System.Data.DataSet
MyCommand.Fill(DtSet)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
ComboBox1.datasource= DtSet.Tables(0) i think this is error

and when I run my combo box will get filled with nSystem.Data.DataRowView

by the way I want only th first row to get imported in my cobo box how is the sql query

thanks in advance

Dani AI

Generated

Two common causes are visible in this thread. As @Hamrick noted, leaving DisplayMember unset produces list entries that show as "System.Data.DataRowView" because each item is a DataRowView. When two ComboBoxes end up showing the same values the usual culprits are: binding both controls to the same shared view or BindingSource and then changing the binding elsewhere; accidentally shadowing the designer control with a local declaration (for example declaring a new variable with the same name inside a method); or using the wrong column name (extra spaces or misspelling).

A reliable pattern is to build a one‑column DataTable (or a separate DataView) for each ComboBox so each list is independent:

' create a one-column table from an existing DataTable (excelTable)
Dim listTable As New DataTable()
listTable.Columns.Add("Text", GetType(String))
For Each r As DataRow In excelTable.Rows
    listTable.Rows.Add(If(r.IsNull("Iso Standards"), "", r("Iso Standards").ToString()))
Next

cbIso.DataSource = listTable
cbIso.DisplayMember = "Text"
cbIso.ValueMember = "Text"

To bind only the first row via OLEDB use a provider query such as:
SELECT TOP 1 [Iso Standards] FROM [Sheet1$]
Also check HDR in the connection string (HDR=Yes treats the first Excel row as column names). Quick checklist: enumerate DataTable.Columns to confirm exact column names, remove any local Dim ComboBox2 As ComboBox that hides the designer control, trim whitespace in column names, and use a separate BindingSource or DataView per ComboBox when independent lists are required. For heavier Excel work the Excel object model (as @shikeb mentioned) or a library like Open XML SDK can be used instead of OLEDB.

Recommended Answers

All 7 Replies

Hi,

Here is a link to Ken Getz's really good artile on manipulating Exel with
VB.NET. It includes the logic you need to extract things such as worksheets
which would allow you to create your ComboBox:

http://msdn.microsoft.com/library/d...ml/ExcelObj.asp

hi
this link is empty and also I searched I could not find the information I wanted please send me the exact link if you know . I would like to know how can I import the data column I want in my excel sheet , in the combo box .
thanks again

and when I run my combo box will get filled with nSystem.Data.DataRowView

You set the data source but not the display member. The display member is the name of the column in the data table that you want to show in the list.

ComboBox1.DataSource = dt.Tables( 0 )
ComboBox1.DisplayMember = "Name"

apchidara, please can you let me have a fully working link - I am working on an application that needs to do a lot of work with Excel.

apchidara, please can you let me have a fully working link - I am working on an application that needs to do a lot of work with Excel.

hi :
which code you need the excel connection code?

hey hamrik
I did it for one comboBox it works and the second I wanted it to be filled with the other column and I put the name of that culumn but u know what ? the combo box will get filled with the previous column that means both ae the same here is the code:

Dim ComboBox2 As ComboBox
ComboBox1.DataSource = DtSet.Tables(0)
ComboBox1.DisplayMember = "Iso Standards"
ComboBox2.DataSource = DtSet.Tables(0)
ComboBox2.DisplayMember = "MVB Standard"

There's no reason that should happen unless you did something else later in the code that changes the bindings.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.