How to convert long into bigint for sp access

  • Thread starter Thread starter Mullin Yu
  • Start date Start date
M

Mullin Yu

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
 
Here is my function:

// Get the Job Items regarding to the JobID

private DataTable getJobItems(long JobID)

{

SqlCommand sqlCommand = new SqlCommand();

sqlCommand.CommandText = "GetJobItems";

sqlCommand.CommandType = CommandType.StoredProcedure;

sqlCommand.Connection = conn;

DataTable results = new DataTable("OutboundQueueItems");

SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sqlCommand );

try

{

//SqlInt64 lngJobID = (Int64) JobID;

SqlInt64 lngJobID = (SqlInt64) JobID;


SqlParameter paramJobID = new SqlParameter("@JobID", SqlDbType.BigInt, 8,
ParameterDirection.Input, false, 0, 0, "JobID", DataRowVersion.Current,
lngJobID);


sqlCommand.Parameters.Add(JobID);


sqlCommand.Connection.Open();

sqlDataAdapter.Fill(results);


}

catch(Exception ex)

{

throw ex;

}

return results;

}
 
Hi Mullin,

Ehmm, the following line is wrong:
sqlCommand.Parameters.Add(JobID);

correct version shuld be (as you should add the parameter itself and not
just the value):
sqlCommand.Parameters.Add(paramJobID);
 
Back
Top