Results 1 to 5 of 5

Thread: VB and database queries

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2007
    Posts
    15

    Exclamation VB and database queries

    I have an issue where I need to in a VB 2005 application call to an MSSQL database ( I already have the SQL figured out) and have the data returned put into a tabbed seperated values text file without using an array.
    Can someone help me figure out this?

    the data is for one value but the amount of names will vary over time.


    Thank you

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: VB and database queries

    The fact that you say that you can't use an array indicates that this is an assignment of some sort, so I'm not going to write any code. What I will say is that you would use nested loops. You could read the data using a DataReader, in which case you'd use a Do or While loop to read the result set row by row and then inside that would be a For loop to read the row field by field.

    Alternatively you could use a DataAdapter to populate a DataTable and then use nested For Each loops or a For loop inside a For Each loop.

    If you won't be using the data again after that I'd suggest the first open. You can open the FAQ thread at the top of the Database Development forum and follow the link to my ADO.NET code examples thread. I believe it includes an example of a DataReader with nested loops.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Frenzied Member Campion's Avatar
    Join Date
    Jul 2007
    Location
    UT
    Posts
    1,098

    Re: VB and database queries

    Do you know how to write to a text file?

    Do you know how to read data returned from a database query?
    From my burrow, 2 feet under.

  4. #4

    Thread Starter
    New Member
    Join Date
    Apr 2007
    Posts
    15

    Re: VB and database queries

    This is not an assignment, but the application will be in WIL after the fact and WIL does not allow array input to the input box. As I am trying to understand the concept I am attempting to do this in vb so then I can get my head around it.
    I do know arrays in vb, but arrays and database are the two worst items in coding for me. I am not really lookiong for code, just an explaination of how to return to a text file from SQL query
    thank you

  5. #5
    Frenzied Member Campion's Avatar
    Join Date
    Jul 2007
    Location
    UT
    Posts
    1,098

    Re: VB and database queries

    Here's an article on how to create, and write to a text file:

    http://www.startvbdotnet.com/files/default.aspx

    Here's an intro on ADO.Net:

    http://www.vbforums.com/showthread.php?t=466658

    Basically, you'll want to use ADO.Net to read the database, and then the Filestream, and Streamwriter classes to write each record's information to your text file.
    From my burrow, 2 feet under.

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