Solved

c# question casting

Posted on 2011-03-12
2
242 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 21

Accepted Solution

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

Author Closing Comment

by:vbnetcoder
ID: 35118775
ty
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Trying to understand what this mean...types(lstTypes[i].AvailableDatatype) 2 38
Create a Dropdown list with sub group 10 43
c#, case, if 4 37
Timeouts during development 3 29
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.
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.
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

738 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