Solved

c# question casting

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

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…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

617 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