mscprojhk
asked on
How to convert long to bigint to access stored procedure
I need to pass a long value from C# to a sql stored procedure, but got error: "SqlParameterCollection accepts non-null sqlParameter type objects, not Int64)
Following is my c# coding
long lngJobID = JobID;
SqlParameter paramJobID = new SqlParameter("@JobID", SqlDbType.BigInt, 8, ParameterDirection.Input, false, 0, 0, "JobID", DataRowVersion.Current, lngJobID);
I can run the sp at Query Analyzer by the following
Declare @JobID as bigint
set @JobID = 20031114000001
EXECUTE GetJobItems @JobID
Following is my c# coding
long lngJobID = JobID;
SqlParameter paramJobID = new SqlParameter("@JobID", SqlDbType.BigInt, 8, ParameterDirection.Input, false, 0, 0, "JobID", DataRowVersion.Current, lngJobID);
I can run the sp at Query Analyzer by the following
Declare @JobID as bigint
set @JobID = 20031114000001
EXECUTE GetJobItems @JobID
ASKER
I found out the bug:
sqlCommand.Parameters.Add( paramJobID );
Should add the object, not the value!
sqlCommand.Parameters.Add(
Should add the object, not the value!
Actually, you can do something as simple as this:
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "UPDATE table1 SET row1=@JobID WHERE ID=@ID";
long JobID;
long ID;
cmd.Parameters.Add("@JobID ",JobID);
cmd.Parameters.Add("@ID",I D);
cmd.Connection = /*connection object*/;
cmd.ExecuteNonQuery();
/* Using this way, you don't even need to specify SqlDbType.BigInt as the Parameters object will automatically match the type of JobID with the column in the MS SQL Table */
I hope my comments help
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "UPDATE table1 SET row1=@JobID WHERE ID=@ID";
long JobID;
long ID;
cmd.Parameters.Add("@JobID
cmd.Parameters.Add("@ID",I
cmd.Connection = /*connection object*/;
cmd.ExecuteNonQuery();
/* Using this way, you don't even need to specify SqlDbType.BigInt as the Parameters object will automatically match the type of JobID with the column in the MS SQL Table */
I hope my comments help
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
object lngJobID = JobID;
SqlParameter paramJobID = new SqlParameter("@JobID", SqlDbType.BigInt, 8, ParameterDirection.Input, false, 0, 0, "JobID", DataRowVersion.Current, lngJobID);