|
-
Jan 18th, 2007, 09:43 AM
#1
Thread Starter
Member
[RESOLVED] Reading multiple Excel columns into VB datagrid
I am trying to load a datagrid from an Excel spreadsheet with data coming from multiple columns (but not necessary next to eachother)
Code:
strsql = "SELECT distinct * FROM [ImportUOM$g:g], [ImportUOM$k:k]"
Dim Conn1 As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & path & ";" & _
"Extended Properties=""Excel 8.0;IMEX=1;HDR=Yes"""
Dim conn2 As New System.Data.OleDb.OleDbConnection(Conn1)
Dim da As New OleDbDataAdapter(strsql, conn2)
Dim objds As New DataSet
da.Fill(objds, "UOMConv")
However - this gives me all combinations from the two columns, whilest I just want G1 and K1, G2 and K2, G3 and K3 etc
How can I get this to work?
-
Jan 18th, 2007, 10:00 AM
#2
Re: Reading multiple Excel columns into VB datagrid
What you're doing is equivalent to specifying two tables, which will produce a join. What you need to do is specify only the columns you want from one table only. I think that this will do the job:
Code:
SELECT F1, F5 FROM [ImportUOM$G:K]
That will select the first and fifth columns from the range specified. The default names for the columns used by the provider are F1, F2, etc.
-
Jan 18th, 2007, 11:47 AM
#3
Thread Starter
Member
Re: Reading multiple Excel columns into VB datagrid
Unfortunately, it gives me "No value given for one or more required parameters" when selecting F1, F2 from that range. Any idea what would be issing?
If I change F1, F2 into "*" it does work
-
Jan 18th, 2007, 04:17 PM
#4
Thread Starter
Member
Re: Reading multiple Excel columns into VB datagrid
What would be the way to select the columns?
-
Jan 18th, 2007, 06:05 PM
#5
Re: Reading multiple Excel columns into VB datagrid
So you're saying that:
Code:
SELECT * FROM [ImportUOM$G:K]
works? If so, what are the names of the resulting DataColumns, i.e. the ColumnName property values of the columns in the resulting DataTable?
-
Jan 19th, 2007, 04:30 AM
#6
Thread Starter
Member
Re: Reading multiple Excel columns into VB datagrid
Wow ... thanks for that tip! That worked a treat now, it was using the header row for column names.
-
Jan 19th, 2007, 05:35 AM
#7
Re: [RESOLVED] Reading multiple Excel columns into VB datagrid
Ah, sorry. I should have noticed that in your original connection string.
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
|