How to get a data type in C# .NET

dboyko

Member
Join Date
Apr 2008
Location
URUGUAY
Posts
17
Hi folks!

Here is mt code in C# and and works fine...

try
{
int Count = 0;
Array PropertyIDs;
Array Descriptions;
Array DataTypes;
ConnectedOPCServer.QueryAvailableProperties(node.Text,
out Count, out PropertyIDs,
out Descriptions, out DataTypes);
....


Here - DataTypes - I have integer value for the data types.

I need convert it from integer value to C# .NET datatype name.
like "int" and etc...

For the Visual Basci it is OK. I have the table for it.

vbEmpty 0 Empty (uninitialized)
vbNull 1 Null (no valid data)
vbInteger 2 Integer
vbLong 3 Long Integer
vbSingle 4 Single
vbDouble 5 Double
vbCurrency 6 Currency value
vbDate 7 Date value
vbString 8 String
vbObject 9 Object
vbError 10 Error value
vbBoolean 11 Boolean value (Zero and Non-zero)
vbVariant 12 Variant. (Array Only)
vbDataObject 13 A data access object.
vbByte 17 Byte
vbUserDefinedType 36 Variants that contain user-defined types
vbArray 8192 Array

But for C# I am looking for any solution....
So, I need convert data calssification integer value to C# .NET data type name.
Please help folks!
 
Done

dboyko said:
Hi folks!

Here is mt code in C# and and works fine...

try
{
int Count = 0;
Array PropertyIDs;
Array Descriptions;
Array DataTypes;
ConnectedOPCServer.QueryAvailableProperties(node.Text,
out Count, out PropertyIDs,
out Descriptions, out DataTypes);
....


Here - DataTypes - I have integer value for the data types.

I need convert it from integer value to C# .NET datatype name.
like "int" and etc...

For the Visual Basci it is OK. I have the table for it.

vbEmpty 0 Empty (uninitialized)
vbNull 1 Null (no valid data)
vbInteger 2 Integer
vbLong 3 Long Integer
vbSingle 4 Single
vbDouble 5 Double
vbCurrency 6 Currency value
vbDate 7 Date value
vbString 8 String
vbObject 9 Object
vbError 10 Error value
vbBoolean 11 Boolean value (Zero and Non-zero)
vbVariant 12 Variant. (Array Only)
vbDataObject 13 A data access object.
vbByte 17 Byte
vbUserDefinedType 36 Variants that contain user-defined types
vbArray 8192 Array

But for C# I am looking for any solution....
So, I need convert data calssification integer value to C# .NET data type name.
Please help folks!

Thanks folks.... yep... It was veeeeery hard to do.

private void timerShowItemsDetails_Tick(object sender, EventArgs e)
{
timerShowItemsDetails.Enabled = false;

if (treeViewGroups.Nodes.Count > 0)
{
TreeNode node = treeViewGroups.SelectedNode;
if (node != null)
{
if (node.Level == 1)
{
try
{
int Count = 0;
Array PropertyIDs;
Array Descriptions;
Array DataTypes;
ConnectedOPCServer.QueryAvailableProperties(node.Text,
out Count, out PropertyIDs,
out Descriptions, out DataTypes);
//
Array PropertyValues;
Array Errors;
ConnectedOPCServer.GetItemProperties(node.Text, Count,
ref PropertyIDs,out PropertyValues, out Errors);

DataTable dataTable = new DataTable();
// Columns
// Uses GetLowerBound and GetUpperBound in the for loop.
for (int i = Descriptions.GetLowerBound(0)-1; i <= Descriptions.GetUpperBound(0)-1; i++)
{
object obj = Descriptions.GetValue(i + 1);
DataColumn column = new DataColumn();
string columnName = (string)obj; // ((string)obj).Replace(" ","");
column.ColumnName = columnName;
object objectDataType = new object();
objectDataType = PropertyValues.GetValue(i + 1);
// Set data types for columns
column.DataType = objectDataType.GetType();
dataTable.Columns.Add(column);
}
// Rows
DataRow row = dataTable.NewRow();
for (int i = PropertyValues.GetLowerBound(0)-1; i <= PropertyValues.GetUpperBound(0)-1; i++)
{
object obj = PropertyValues.GetValue(i + 1);
row[dataTable.Columns.ColumnName] = obj;
}
dataTable.Rows.Add(row);
dataGridViewItemProperties.DataSource = dataTable;
}
catch (Exception ex)
{
string s = "Cannot get properties for item " + treeViewGroups.SelectedNode.Text + " : " + ex.Message;
eventLogMain.WriteEntry(s, EventLogEntryType.Error);
dataGridViewLog.Rows.Add(global::MegaOPCClient.Properties.Resources.Error, DateTime.Now, s);
}

}
}
}
}

 

Similar Topics

I cannot add SLC500 analog input tag (I: 8.3) to EZSeries Touch Panel Editor (V 5.3). I used all the listed tag datatype but it all says "Invalid...
Replies
10
Views
310
Hi guys, I have no experience when working with AllenBradley PLC, but I hope someone could clarify the result of multiplication shown in the...
Replies
14
Views
2,262
Trying to get data types (AS Structures) to update after a new tag import is made from PLC. WinCC can show red if an existing element was removed...
Replies
0
Views
290
Is there a way to use LREAL Data type on L71. I am getting 64 bit Double (IEEE754 Double precision 64-bit) data from a modbus device onto PLC via...
Replies
6
Views
989
Back
Top Bottom