Solved

c# question casting

Posted on 2011-03-12
2
239 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 500 total points
ID: 35118733
return (int)Command.ExecuteScalar();
0
 

Author Closing Comment

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

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…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

862 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

24 Experts available now in Live!

Get 1:1 Help Now