Results 1 to 2 of 2

Thread: String to Datagrid

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2001
    Posts
    416

    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!

  2. #2
    Frenzied Member Asgorath's Avatar
    Join Date
    Sep 2004
    Location
    Saturn
    Posts
    2,036

    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:
    1. ' Create a DataTable.
    2.     Dim myTable As DataTable = new DataTable("myTable")
    3.     ' Create a DataColumn and set various properties.
    4.     Dim myColumn As DataColumn = New DataColumn
    5.     myColumn.DataType = System.Type.GetType("System.Decimal")
    6.     myColumn.AllowDBNull = False
    7.     myColumn.Caption = "Price"  
    8.     myColumn.ColumnName = "Price"
    9.     myColumn.DefaultValue = 25
    10.     ' Add the column to the table.
    11.     myTable.Columns.Add(myColumn)
    12.     ' Add 10 rows and set values.
    13.     Dim myRow As DataRow
    14.     Dim i As Integer  
    15.     For i = 0 to 9
    16.        myRow = myTable.NewRow()
    17.        myRow("Price") = i + 1
    18.        ' Be sure to add the new row to the DataRowCollection.
    19.        myTable.Rows.Add(myRow)
    20.     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
  •  



Click Here to Expand Forum to Full Width