Solved

How to convert long to bigint to access stored procedure

Posted on 2003-12-08
5
395 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

770 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