- Is it possible to send a text file of csv values to a parameter in a stored procedure?
- how do send the the text file from winforms to stored procedure?
- How do i create a parameter in stored procedure to accept that text file?
thanks
thanks
You can pass the path to the file into the stored procedure as a simple "nvarchar(260)" parameter, though the Sql Server process will need to have read access to that file path (i.e., you either need to copy it to a share on the sql server itself from the WinForms app, or it needs to be on a network share that the Sql Server account has access to).
Once you have the path in the stored procedure, you can use a Bulk Insert process; see this thread on how to use Bulk Load from within a stored procedure: Bulk insert using stored procedure or this thread to load it into a temp table to work with: How to BULK INSERT a file into a *temporary* table where the filename is a variable?.
That being said, a better approach would be to convert the CSV file to Xml in the WinForms app, then pass Xml as a string to the stored procedure. Sql Server 2005 and later have good support for Xml parameters, enabling you to query them. (Personally I would take this latter approach). The Xml type is just one of the available parameter types, so you end up passing it like you would a string parameter. Working with Xml in the Stored Procedure will be much easier (and better supported) than the CSV will be.