/*
I found a Bug about the InputOutput parameter in SqlHelper v3.1? V2.1 old version!
Data Access Application Block 3.1
Http://www.gotdotnet.com/workspaces/workspace.aspx? C20d12b0-af52-402b-9b7c-aaeb21d1f431
-- Create the following stored procedure
Create proc sp_swap
@ X int out
, @ Y int out
As
-- If it is declared as an OutPut parameter and is also used as an Input parameter,
-- The ExecuteXXXX of SqlHelper v3.1 cannot correctly obtain the output parameter assigned by SP.
Set @ x = @ x + @ y
Set @ y = @ x-@ y
Set @ x = @ x-@ y
Select id, @ x, @ y
From
(
Select 1 as id
Union all
Select 2
Union all
Select 3
Union all
Select 4
Union all
Select 5
) T
*/
Using System;
Using System. Data;
Using System. Xml;
Using System. Data. SqlClient;
Using System. Collections;
Using Microsoft. ApplicationBlocks. Data;
Public class Class1
{
Static void Main (string [] args)
{
System. Data. SqlClient. SqlConnection SC = new System. Data. SqlClient. SqlConnection ("Server = devserver; Database = test; User ID = sa; Password = devdos ");
String spName = "sp_swap ";
SqlParameter [] spa = SqlHelperParameterCache. GetSpParameterSet (SC, spName );
Spa [0]. Value = 3;
// You must explicitly re-specify spa [0]. Direction as ParameterDirection. InputOutput.
// Or modify the source code of SqlHelper
// Spa [0]. Direction = ParameterDirection. InputOutput;
Spa [1]. Value = 5;
// Spa [1]. Direction = ParameterDirection. InputOutput;
DataSet ds = SqlHelper. ExecuteDataset (SC, CommandType. StoredProcedure, spName, spa );
PrintDataSet (ds );
System. Console. WriteLine ("Parameter X: {0}", spa [0]. Value );
System. Console. WriteLine ("Parameter Y: {0}", spa [1]. Value );
}
Static void PrintDataSet (DataSet ds)
{
Foreach (DataTable dt in ds. Tables)
{
System. Console. WriteLine (dt. TableName );
Foreach (DataColumn dc in dt. Columns)
{
System. Console. Write (dc. ColumnName + "/t ");
}
System. Console. WriteLine ();
Foreach (DataRow dr in dt. Rows)
{
Foreach (DataColumn dc in dt. Columns)
{
System. Console. Write (dr [dc] + "/t ");
}
System. Console. WriteLine ();
}
// System. Console. ReadLine ();
// System. console. writeLine ("/n ====================================== ==================== ");
}
}
}
/*
After debugging, it is found that the problem is GetParameterDirection. This method is used in namespace GotDotNet. ApplicationBlocks. Data:
SqlServer. cs, because this method is only used for SQL Server, it should be no problem to change this program
/// <Summary>
/// Converts the OleDb parameter direction
/// </Summary>
/// <Param name = "oledbDirection"> The integer parameter direction </param>
/// <Returns> A ParameterDirection </returns>
Private static ParameterDirection GetParameterDirection (short oledbDirection)
{
ParameterDirection pd;
Switch (oledbDirection)
{
Case 1:
Pd = ParameterDirection. Input;
Break;
Case 2: // or simply comment out all of case 2
Pd = ParameterDirection. Output; // is the problem here
Goto default; // the sentence I added
// Break; // the sentence I commented out
Case 4:
Pd = ParameterDirection. ReturnValue;
Break;
Default:
Pd = ParameterDirection. InputOutput;
Break;
}
Return pd;
}
}
*/