Solved

How to convert long to bigint to access stored procedure

Posted on 2003-12-08
5
388 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
Comment Utility
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
Comment Utility
I found out the bug:

sqlCommand.Parameters.Add(paramJobID);

Should add the object, not the value!
0
 

Expert Comment

by:sentosa_gani
Comment Utility
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
Comment Utility
PAQed, with points refunded (20)

PashaMod
Community Support Moderator
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now