Home All Groups Group Topic Archive Search About

Can I write and read a STRUCTURE to a file or to a Database???

Author
13 Jul 2006 4:54 AM
Hexman
Hi All,

I have created a structure for a record (as I did in the old days with assembler, cobol, etc.).  It contains several fields with various types.  Using
it in arrays it functions nicely.  Much the same as a datarow.  I'm acquiring transactions from different sources, parsing them, validating them and
placing the data into the structure.  Now, I want to write these transactions to a file.

How do I write the entire structure (one entry) to a streamwriter???  Is it possible to create a datatable with the same fields and structure and add
a row with one statement (moving the structure to the datarow)???

Just trying to organize a bit better and have flexibility (write to db or file).

Thanks,

Hexman


-----------------------------------------------------------------------------------------------------
Public Structure TransRecord
        Dim TDate As Date
        Dim TPONum As String
        Dim TAmt As Double
    End Structure
....

Dim TR as New TransRecord

TR.TDate = "06/12/06"
TR.TPONum = "12345-A"
TR.TAmt = 1450.25

Can I do something like the following?

streamWriter.Write(TR)

or

Dim dtTrans As New DataTable
Dim drTrans as New DataRow

dtTrans(0) = TR


----------------------------------------------------------------------------------------------------------

Author
13 Jul 2006 6:06 AM
GhostInAK
Hello Hexman,

Sure.  Check out the various serialization mechanisims in .NET.  Fuirst one
that comes to mind is System.Xml.Serialization.XmlSerializer

-Boo

Show quoteHide quote
> Hi All,
>
> I have created a structure for a record (as I did in the old days with
> assembler, cobol, etc.).  It contains several fields with various
> types.  Using
>
> it in arrays it functions nicely.  Much the same as a datarow.  I'm
> acquiring transactions from different sources, parsing them,
> validating them and
>
> placing the data into the structure.  Now, I want to write these
> transactions to a file.
>
> How do I write the entire structure (one entry) to a streamwriter???
> Is it possible to create a datatable with the same fields and
> structure and add
>
> a row with one statement (moving the structure to the datarow)???
>
> Just trying to organize a bit better and have flexibility (write to db
> or file).
>
> Thanks,
>
> Hexman
>
> ----------------------------------------------------------------------
> -------------------------------
> Public Structure TransRecord
> Dim TDate As Date
> Dim TPONum As String
> Dim TAmt As Double
> End Structure
> ...
> Dim TR as New TransRecord
>
> TR.TDate = "06/12/06"
> TR.TPONum = "12345-A"
> TR.TAmt = 1450.25
> Can I do something like the following?
>
> streamWriter.Write(TR)
>
> or
>
> Dim dtTrans As New DataTable
> Dim drTrans as New DataRow
> dtTrans(0) = TR
>
> ----------------------------------------------------------------------
> ------------------------------------
>
Author
13 Jul 2006 7:12 AM
Hexman
Thanks, I'll check into it.

On Thu, 13 Jul 2006 06:06:16 +0000 (UTC), GhostInAK <ghosti***@gmail.com> wrote:

Show quoteHide quote
>Hello Hexman,
>
>Sure.  Check out the various serialization mechanisims in .NET.  Fuirst one
>that comes to mind is System.Xml.Serialization.XmlSerializer
>
>-Boo
>
>> Hi All,
>>
>> I have created a structure for a record (as I did in the old days with
>> assembler, cobol, etc.).  It contains several fields with various
>> types.  Using
>>
>> it in arrays it functions nicely.  Much the same as a datarow.  I'm
>> acquiring transactions from different sources, parsing them,
>> validating them and
>>
>> placing the data into the structure.  Now, I want to write these
>> transactions to a file.
>>
>> How do I write the entire structure (one entry) to a streamwriter???
>> Is it possible to create a datatable with the same fields and
>> structure and add
>>
>> a row with one statement (moving the structure to the datarow)???
>>
>> Just trying to organize a bit better and have flexibility (write to db
>> or file).
>>
>> Thanks,
>>
>> Hexman
>>
>> ----------------------------------------------------------------------
>> -------------------------------
>> Public Structure TransRecord
>> Dim TDate As Date
>> Dim TPONum As String
>> Dim TAmt As Double
>> End Structure
>> ...
>> Dim TR as New TransRecord
>>
>> TR.TDate = "06/12/06"
>> TR.TPONum = "12345-A"
>> TR.TAmt = 1450.25
>> Can I do something like the following?
>>
>> streamWriter.Write(TR)
>>
>> or
>>
>> Dim dtTrans As New DataTable
>> Dim drTrans as New DataRow
>> dtTrans(0) = TR
>>
>> ----------------------------------------------------------------------
>> ------------------------------------
>>
>