Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 197
  • Last Modified:

Array into Temp Files

Hello all,

I need to query a db and eventually split the data results into temp files.

I need to query a database based on three fields “myID”, “myTry” and “myDate”. Myid is a client id number, myTry is the number of times they have been contacted, and myDate is the particular time when a notification is set to go out.

I need to query the database once (select myID, myTry, myAmt, myItem from mytable where myDate = '" & txtMYDATE.text &"'). A user enters in myDate. I need to create an array that will split the data into groups:

All of the
myId's = 00001 and myTry = 1 need to be grouped together
myId's = 00001 and myTry = 2 need to be grouped together
myId's = 00002 and myTry = 1 need to be grouped together
…etc

Each result set needs to be written into temp files (csv, txt).

Please help!

Thanks
-mack1er
0
mack1er
Asked:
mack1er
  • 2
1 Solution
 
Wim_BlCommented:
Hi,

create your recordset with this query:

select myID, myTry, myAmt, myItem from mytable where myDate = '" & txtMYDATE.text &"' group by myId, myTry order by myID

This will group your data.  Now write every record to a file, using a textWriter object. Eventually add a delimiter after each record. If you need help on how to loop through the recordset, please post your question under this comment.

greetings
0
 
mack1erAuthor Commented:
Win_Bl,

Thank you for pointing me in the right direction. Yes, I could use a little help looping through the recordset.

Thanks in advance,
 -mack1er
0
 
Wim_BlCommented:
Hi,

this is the way I usually loop through a recordset (only started using VB.NET recently, so maybe there are better ways). I put my recordset in a dataSet object, say ds. I put the records in say tblMyTable. You also need an sql-statement and a connection object. The code is just off the top of my head, so there might (will?) be errors in it, but you'll get the idea.

dataAdapter.selectCommand.commandText = sql-statement
dataAdapter.selectCommand.connection = connection-object
dataAdapter.selectCommand.connection.open()
dataAdapter.fill(ds,"tblMyTable")
dataAdapter.selectCommand.connection.close()

The data you require is now in your dataSet. Looping through it:

dim dr as dataRow

for each dr in ds.tables("tblMyTable").Rows
     dim myID as integer
     dim myTry as integer

     myID = dr.item("myID")
     myTry = dr.item("myTry")
     .....  ' process the data here, for instance write it to a file
next


Hope this helps you out. As for the file-writing, don't know the syntax right away, so maybe google for it.

greetings,
Wim
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now