Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

c# question casting

Posted on 2011-03-12
2
Medium Priority
?
247 Views
Last Modified: 2012-05-11
The code gives me the error. I am new to C# so not sure why

Error      6      Cannot implicitly convert type 'object' to 'int'. An explicit conversion exists (are you missing a cast?)      

public int ReturnCountProductName(string ProductName)
	{

		System.Data.SqlClient.SqlCommand Command = new System.Data.SqlClient.SqlCommand();

		Command.Connection = Connection;
		Command.CommandText = "spReturnProductCountByProductName ";
		Command.Parameters.AddWithValue("@Product_Name", ProductName);
		Command.CommandType = CommandType.StoredProcedure;
		return Command.ExecuteScalar();

	}

Open in new window

0
Comment
Question by:vbnetcoder
2 Comments
 
LVL 21

Accepted Solution

by:
Dale Burrell earned 2000 total points
ID: 35118733
return (int)Command.ExecuteScalar();
0
 

Author Closing Comment

by:vbnetcoder
ID: 35118775
ty
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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
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.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

972 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