Solved

c# question casting

Posted on 2011-03-12
2
238 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

759 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

22 Experts available now in Live!

Get 1:1 Help Now