Wednesday, February 02, 2005

Error in Microsoft Application Block

Took me two days to overcome this problem. According to Microsoft documentation about using the data access application block when passing parameters we should something like this:

SqlHelper.ExecuteNonQuery(connectionString,"My_Stored_Procedure",param1,param2,param3);
Unfortunately this does not work and we need to supply more parameters. In the Microsoft examples they used param1,param2,param3 as a simple variable which is not the case.

Here is the right way of doing the same thing.

SqlHelper.ExecuteNonQuery(connectionString,CommandType.StoredProcedure,"My_Stored_Procedure"
,new SqlParameter("@Param1",param1),
new SqlParameter("@Param2",param2),
new SqlParameter("@Param3",param3));

And now that should work !

No comments: