rohitigupta Posted November 6, 2012 Report Share Posted November 6, 2012 Hello, i am new to Unitronics forum, we have started new project on Unitronics Vision 130 PLC, now i have to transfer data from aso.net datatable to unitronics datatable and unitronics datatable to ADO.net data table, can i do this, is there any example for this. Please guide me its very urgent. Link to comment Share on other sites More sharing options...
Saragani Posted November 6, 2012 Report Share Posted November 6, 2012 The main question is why... For what purpose? Link to comment Share on other sites More sharing options...
rohitigupta Posted November 6, 2012 Author Report Share Posted November 6, 2012 Hello Saragani, I have to update PLC data tables based on data in my database. for this only i want to convert ADO.net data tables to Unitronics Data table. I just want function to convert between both. Thanks and Regards.. Rohit Gupta Link to comment Share on other sites More sharing options...
Saragani Posted November 6, 2012 Report Share Posted November 6, 2012 This is a concept: private System.Data.DataTable getDataTableFromTable(Unitronics.DataTables.Table table) { System.Data.DataTable result = new DataTable(); foreach (var col in table.Columns) { DataColumn column = new DataColumn(col.Name, getTypeOfColumn(col)); result.Columns.Add(column); } foreach (var row in table.Rows) { var resultRow = result.NewRow(); int colIndex = 0; foreach (var cell in row.Cells) { resultRow[colIndex] = cell.Fields[0]; colIndex++; } } return result; } private void setDataTableValuesIntoTable(System.Data.DataTable dataTable, Unitronics.DataTables.Table table) { int rowIndex = 0; foreach (DataRow row in dataTable.Rows) { int cellIndex = 0; foreach (var cell in row.ItemArray) { table.Rows[rowIndex].Cells[cellIndex].Fields[0].Value = cell; cellIndex++; } rowIndex++; } } private Type getTypeOfColumn(Unitronics.DataTables.Columns.Column col) { Type result; switch (col.Type) { case FieldType.Boolean: result = typeof(bool); break; case FieldType.Byte: result = typeof(byte); break; case FieldType.Int16: result = typeof(short); break; case FieldType.Int32: result = typeof(int); break; case FieldType.UInt16: result = typeof(ushort); break; case FieldType.UInt32: result = typeof(uint); break; case FieldType.Float: result = typeof(float); break; case FieldType.String: result = typeof(string); break; case FieldType.Timer: result = typeof(TimeSpan); break; default: throw new NotImplementedException(); } return result; } I didn't test it... Basically, one function returns a DataTable from the Unitronics Data Table, and the other one fills a Unitronics DataTable from a Data Table (This is because we don't let you create a Unitronics Data Table, and you shouldn't). Link to comment Share on other sites More sharing options...
rohitigupta Posted November 7, 2012 Author Report Share Posted November 7, 2012 Thanks, I will test it and get back to you. Thanks again. Rohit Gupta Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now