C
Charles Crawford
I'm having problems getting correct parameter values to pass to SQL Server
from C# code.
In my C# code, I assign a parameter '@appID' and give it a value based on
the option chosen by a user.
No matter what I select when debugging, the code always passes a value of
'1' to the stored procedure.
The stored procedure is as follows:
CREATE PROCEDURE [dbo].[spLockApplication]
@appID int
AS
UPDATE tblApplications SET isLocked = 1 where appID = @appID
GO
The C# code that uses this sp is as follows:
string connString =
System.Configuration.ConfigurationManager.AppSettings["connectionString"].ToString();
SqlConnection myConn = new SqlConnection(connString);
SqlParameter myAppID = new SqlParameter("@appID", SqlDbType.Bit);
myAppID.Value = applicationID;
SqlCommand myCmd = new SqlCommand("spLockApplication", myConn);
myCmd.CommandType = CommandType.StoredProcedure;
myCmd.Parameters.Add(myAppID);
myConn.Open();
myCmd.ExecuteNonQuery();
myConn.Close();
Debugging the C# code shows that prior to execution, applicationID has the
correct value. If the value is 2, for instance, the data row with appID =
@appID should be the target row for the update operation. The only affected
record, however, is the row with appID = 1.
Any ideas?
Thanks,
Charlie
from C# code.
In my C# code, I assign a parameter '@appID' and give it a value based on
the option chosen by a user.
No matter what I select when debugging, the code always passes a value of
'1' to the stored procedure.
The stored procedure is as follows:
CREATE PROCEDURE [dbo].[spLockApplication]
@appID int
AS
UPDATE tblApplications SET isLocked = 1 where appID = @appID
GO
The C# code that uses this sp is as follows:
string connString =
System.Configuration.ConfigurationManager.AppSettings["connectionString"].ToString();
SqlConnection myConn = new SqlConnection(connString);
SqlParameter myAppID = new SqlParameter("@appID", SqlDbType.Bit);
myAppID.Value = applicationID;
SqlCommand myCmd = new SqlCommand("spLockApplication", myConn);
myCmd.CommandType = CommandType.StoredProcedure;
myCmd.Parameters.Add(myAppID);
myConn.Open();
myCmd.ExecuteNonQuery();
myConn.Close();
Debugging the C# code shows that prior to execution, applicationID has the
correct value. If the value is 2, for instance, the data row with appID =
@appID should be the target row for the update operation. The only affected
record, however, is the row with appID = 1.
Any ideas?
Thanks,
Charlie