Merging DataSets

brix_zx2

Member
Joined
Apr 6, 2005
Messages
12
Location
Altus AFB
Programming Experience
1-3
Got the following code to load my excel data into a dataset. The dataset
merge command I'm trying to use must not be right because it's not working.
Anyone see the problem?

VB.NET:
[size=2][color=#0000ff]Dim[/color][/size][size=2] DataSet [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]New[/color][/size][size=2] DataSet[/size]
[size=2][color=#0000ff]Dim[/color][/size][size=2] MyConnection [/size][size=2][color=#0000ff]As[/color][/size][size=2] System.Data.OleDb.OleDbConnection[/size]
 
 
[size=2]MyConnection = [/size][size=2][color=#0000ff]New[/color][/size][size=2] System.Data.OleDb.OleDbConnection( _[/size]
[size=2]"provider=Microsoft.Jet.OLEDB.4.0; " & _
"data source=C:\Program Files\97CS\SelfInspect\CheckList\NewCheckList.XLS; " & _
"Extended Properties=Excel 8.0;")
 
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] cmd = [/size][size=2][color=#0000ff]New[/color][/size][size=2] OleDb.OleDbCommand("SELECT * FROM [Sheet1$]", [/size][size=2]MyConnection) [/size][size=2][color=#008000]'Sheet1 = Wookbookname append "$"[/color][/size]
[size=2][color=#0000ff]Dim[/color][/size][size=2] adap [/size][size=2][color=#0000ff]As[/color][/size][size=2] OleDb.OleDbDataAdapter = [/size][size=2][color=#0000ff]New[/color][/size][size=2] OleDb.OleDbDataAdapter(cmd)
[/size]
 
[size=2][color=#0000ff]Try[/color][/size]
 
 
[size=2]adap.SelectCommand = cmd
adap.Fill(DataSet)
[/size]
 
[size=2][color=#008000]' Merge the table into the DataSet.[/color][/size]
[size=2]Console.WriteLine("Merging")
DsAddItems.AcceptChanges()
DsAddItems.Merge(DataSet, [/size][size=2][color=#0000ff]False[/color][/size][size=2], MissingSchemaAction.Add)[/size]
[size=2]DataGrid1.DataSource = DataSet.Tables(0).DefaultView
[/size]
 
[size=2][color=#0000ff]Catch[/color][/size][size=2] exp [/size][size=2][color=#0000ff]As[/color][/size][size=2] Exception[/size]
[size=2]MsgBox(exp.Message)
[/size]
 
[size=2][color=#0000ff]End[/color][/size][size=2][color=#0000ff]Try
[/color][/size]
 
Merging Datasets

Hi,

I'm trying to do the same thing.
Think your problem is in the line...
DataGrid1.DataSource = DataSet.Tables(0).DefaultView
I have been using..
DataGrid1.DataSource = Excel_Import_DO1.Delivery_Order
where 'Delivery_Order' is the worksheet name.
However still cant get the merge to work :confused:

Jacks
 
Back
Top