Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to save a storedproc result set to a text file? 1

Status
Not open for further replies.

darwin101

Programmer
Mar 7, 2001
156
US
Hi all

How would I go about using VB.net 2003 to execute a stored proc, then save the result set out to a text file (csv)?
I would then need to use another button to rename and move that same file after it is used. Any suggestions will be appreciated.
This is for a non profit,we don't have any real language programmers. I spent a few hours last nite at the book store trying to find something similar, no luck.

Thanks
 
This is how you can execute Stored Proc and save the result in DataSet object.
Code:
Dim DS As New DataSet
Dim Conn As New SqlConnection("Server=yourServer;Uid=yourUserID;pwd=yourPassword;Database=yourDatabase;")
Dim DA As New SqlDataAdapter

'Set Select Command for DA.
DA.SelectCommand = New SqlCommand
With DA.SelectCommand
    .Connection = Conn
    .CommandType = CommandType.StoredProcedure
    .CommandText = "yourProcedureName"
    .Parameters.Clear()
    .Parameters.Add("@yourVariable", yourValue)
End With

DA.Fill(DS, "yourTableName")
ofcourse, don't forget to include the following namespace

Imports System.Data.SqlClient


Use the following to see how you can write text file from DataSet.


 
Thanks for your help and advice, this should get me going.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top