Custom select return types

The procedure is:


CREATE PROCEDURE spGetCities
	@fkState int
AS
BEGIN
	SET NOCOUNT ON;
	SELECT CityName FROM CITIES where pkState = @pkState
END
GO


And method


public DataTable getDataTable (int pkState)  {

           Command command = new Command();
           command.CommandType = CommandType.StoredProcedure;

           //add values to object
           command.AddWithValue("pkState", pkState);
            
           return (DataTable)(command.ExecuteQuery("spGetCities", ReturnType.DataTable));

}


You can return other types:
  • DataReader

 (DataReader)(command.ExecuteQuery("spGetCities", ReturnType.DataReader));

  • DataSet

 (DataSet)(command.ExecuteQuery("spGetCities", ReturnType.DataSet));

  • DataView

 (DataView)(command.ExecuteQuery("spGetCities", ReturnType.DataView));


Read more about types:

Return Scalar.
Return XmlDocument.

Last edited Feb 10, 2009 at 10:21 AM by paulovich, version 5

Comments

No comments yet.