Showing posts with label store procedure. Show all posts
Showing posts with label store procedure. Show all posts

Sunday, September 12, 2010

Database, Writing In-Memory Data Tables to an XML File

Problem

You have some data in a DataSet object, and you would like to export it to an XML file for later reimportation.

Solution

Use the DataSet's WriteXML() method to send the DataSet content to the file in a common XML format.

Discussion

Recipe 13.8 builds a DataTable object with two state-specific records. The following code adds that table to a DataSet object and writes its records to an XML file:
Dim fullDataSet As New Data.DataSet
 fullDataSet.Tables.Add(stateTable)
 fullDataSet.WriteXml("C:\StateInfo.xml")

Database, Using Stored Procedures


Problem

You need to use a stored procedure in your database, and you're not sure how to specify values for its input and output parameters.

Solution

Use the command object's Parameters collection to set and retrieve stored procedure argument values.

Discussion

Here's a simple SQL Server stored procedure that does nothing more than retrieve a field from a table given its ID value:
CREATE PROCEDURE GetRecordName
    @PriKey int,
    @NameResult varchar(50) OUT
 AS
 BEGIN
    -- Given an ID value, return the RecordName field.
    SET @NameResult =
       (SELECT RecordName FROM Table1 WHERE ID = @PriKey);
 END