Solved

How to convert long to bigint to access stored procedure

Posted on 2003-12-08
5
397 Views
Last Modified: 2010-04-16
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
0
Comment
Question by:mscprojhk
5 Comments
 
LVL 18

Expert Comment

by:testn
ID: 9895968
You can simply change it to

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

Author Comment

by:mscprojhk
ID: 9901114
I found out the bug:

sqlCommand.Parameters.Add(paramJobID);

Should add the object, not the value!
0
 

Expert Comment

by:sentosa_gani
ID: 9909462
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",ID);
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
0
 

Accepted Solution

by:
PashaMod earned 0 total points
ID: 11743430
PAQed, with points refunded (20)

PashaMod
Community Support Moderator
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question