|
-
Nov 3rd, 2004, 04:30 AM
#1
Thread Starter
Hyperactive Member
String to Datagrid
Hi,
I'm writing a system that will interact with MQ and get message for different function from it. Message structure will be different for different function.
Each message consist of many records, e.g.:
C001John 20040510C002Peter 20030115
and what I need to do is to write a generic class, such that when I pass in the message definition and message itself, it will help to built the DataTable, and parse records from message to insert to the dt. Then, I can use Datagrid to display the DataTable.
At first, it seems logical to use Structure to define the "table", however, I found no way to define the size of each structure element. Later, I think of a solution, which is to define a "Field" structure first which will store the name, size and value.
Now, I can declare each structure element as "Field.
Structure Fld
size as integer
name as string
value as string
end structure
Structure Record
CustID as Fld
Name as Fld
But I soon run into another trouble on how to loop through each item in the structure
So, I think of using XML to define the schema, and then use a DataSet function to generate the DataTable directly. I have defined some simplyType in the XML schema, e.g.:
<xs:simpleType name="USERID">
<xs:restriction base="xs:string">
<xs:length value="3" />
</xs:restriction>
</xs:simpleType>
When I try to reference the MaxLength or corresponding column in the DataTable, it return -1 to me. What I need is the field length in order to get substring from the message to put it to the correct position.
Can someone suggest a proper way to handle this? I have no idea on how to implement it.
Thx a lot!
-
Nov 3rd, 2004, 06:12 AM
#2
Re: String to Datagrid
Originally posted by stm
Hi,
I'm writing a system that will interact with MQ and get message for different function from it. Message structure will be different for different function.
Each message consist of many records, e.g.:
C001John 20040510C002Peter 20030115
and what I need to do is to write a generic class, such that when I pass in the message definition and message itself, it will help to built the DataTable, and parse records from message to insert to the dt. Then, I can use Datagrid to display the DataTable.
Hi
I'm not sure i understand what you want but when are adding a DataColumn to your datatable you can define its type like this
VB Code:
' Create a DataTable.
Dim myTable As DataTable = new DataTable("myTable")
' Create a DataColumn and set various properties.
Dim myColumn As DataColumn = New DataColumn
myColumn.DataType = System.Type.GetType("System.Decimal")
myColumn.AllowDBNull = False
myColumn.Caption = "Price"
myColumn.ColumnName = "Price"
myColumn.DefaultValue = 25
' Add the column to the table.
myTable.Columns.Add(myColumn)
' Add 10 rows and set values.
Dim myRow As DataRow
Dim i As Integer
For i = 0 to 9
myRow = myTable.NewRow()
myRow("Price") = i + 1
' Be sure to add the new row to the DataRowCollection.
myTable.Rows.Add(myRow)
Next i
Regards
Jorge
"The dark side clouds everything. Impossible to see the future is."
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|