tora111
asked on
Assign datatable from DataSet
I want to assign a datatable to another datatable (create from a datasoruces)
Dim mdtPO As New OrderTrackingDataSet.Order MasterData Table '<--- data table created by datasources
cnn.Open()
mDA = New System.Data.OleDb.OleDbDat aAdapter(" Select * from " & mTableName, mCnn)
mDA.Fill(mDS, mTableName)
mCB = New System.Data.OleDb.OleDbCom mandBuilde r(mDA)
mdtPO = mDS.Tables(mTableName)
cnn.Close()
However I got the following error message !
"Unable to cast object of type 'System.Data.DataTable' to type 'OrderMasterDataTable'."
So how can I assign datatable "mDS.Tables(mTableName)" to mdtPO ?
Thanks in advance!
Dim mdtPO As New OrderTrackingDataSet.Order
cnn.Open()
mDA = New System.Data.OleDb.OleDbDat
mDA.Fill(mDS, mTableName)
mCB = New System.Data.OleDb.OleDbCom
mdtPO = mDS.Tables(mTableName)
cnn.Close()
However I got the following error message !
"Unable to cast object of type 'System.Data.DataTable' to type 'OrderMasterDataTable'."
So how can I assign datatable "mDS.Tables(mTableName)" to mdtPO ?
Thanks in advance!
ASKER
Arthur_Wood,
It got the same error "Unable to cast object of type 'System.Data.DataTable' to type 'OrderMasterDataTable'."
It seems cannot assign to a datataboe to a datatable(from data sources, xsd) directly !!!
It got the same error "Unable to cast object of type 'System.Data.DataTable' to type 'OrderMasterDataTable'."
It seems cannot assign to a datataboe to a datatable(from data sources, xsd) directly !!!
I would guess that 'OrderMasterDataTable' is a class which inherits from a datatable with some methods thrown in for fun and profit. You might need to add the records one at a time.
How is mDS declared and set?
Bob
Bob
ASKER
OrderTrackingDataSet a xsd is created by data sources
mDS is a dataset
mDS is a dataset
mDs should be OrderTrackingDataSet, and not just plain ol' DataSet.
Bob
Bob
ASKER
Bob, it doesn't a matter! My objective is to allow add/change/delete the "OrderTrackingDataSet.Orde rMasterDat aTable" by coding.
Is it possible to use coding method to manipulate a xsd datatable ?
Is it possible to use coding method to manipulate a xsd datatable ?
It does matter if you are trying to cast a DataTable from the strong type DataSet into a strong type.
Bob
Bob
ASKER
I see, in other words, is it possible to manipulate a datatable from a strong type dataset by coding method ? Because I don't know how to ...., could you give me some example for it !
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Bob, I'm wonder if we can use tableadapter and bindingsource to manipulate the strong type dataset table then it'll be more simple.
But I don't how to change the database source (for example a mdb file), I don't want to hard code the database because sometimes we need to deploy to different location and mdb file!!!
But I don't how to change the database source (for example a mdb file), I don't want to hard code the database because sometimes we need to deploy to different location and mdb file!!!
Dim mdtPO As New OrderTrackingDataSet.Order
cnn.Open()
mDA = New System.Data.OleDb.OleDbDat
mDA.Fill(mDS, mTableName)
mCB = New System.Data.OleDb.OleDbCom
mdtPO = cType( mDS.Tables(mTableName), OrderTrackingDataSet.Order
cnn.Close()
AW