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. Quote 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? Quote 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 Quote 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). Quote 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.