Solved

How to convert long to bigint to access stored procedure

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Round up to 100% in .NET 10 80
C# Connection String for Oracle database is not working 22 88
Performance  Html.BeginForm vs jQuery 3 45
Entity Framework 7 28
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

919 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

12 Experts available now in Live!

Get 1:1 Help Now