Solved

syntax C#

Posted on 2011-03-14
5
190 Views
Last Modified: 2012-05-11
In the attached code I get the following errors:

public int DeleteProductByProductID(string ProductID)
ERROR = Expected class, delegate, enum, interface, or struct      
   

command.Parameters["@Product_ID"].Value = ProductID;

}
ERROR=Type or namespace definition, or end-of-file expected
public int DeleteProductByProductID(string ProductID)
    {

        System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand("spDeleteProductByProductID ", Connection);
        //Add the parameters for the SelectCommand.


        command.Parameters.Add("@Product_ID", SqlDbType.Int);
        command.Parameters["@Product_ID"].Value = ProductID;
        command.CommandType = CommandType.StoredProcedure;
        return Convert.ToInt32(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
  • 2
5 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 35128273
That would suggest you are trying to define your method outside of a class, which isn't allowed.
0
 

Author Comment

by:vbnetcoder
ID: 35128286
I am converting from vb.net using a converter tool but finding a ton of errors.  I don't know how to fix most of them..
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 35128343
Is that method from a Module in VB? C# doesn't support modules in the same way that VB does, so the method will need to be in a class. If your don't need to create an instance of the class then you can make it static, but it still needs to be defined within a class.

Something like:
public static class ProductManager
{
public static int DeleteProductByProductID(string ProductID)
    {

        System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand("spDeleteProductByProductID ", Connection);
        //Add the parameters for the SelectCommand.


        command.Parameters.Add("@Product_ID", SqlDbType.Int);
        command.Parameters["@Product_ID"].Value = ProductID;
        command.CommandType = CommandType.StoredProcedure;
        return Convert.ToInt32(command.ExecuteScalar());

    }
}

// called like
ProductManager.DeleteProductByProductID("1");

Open in new window

0
 
LVL 2

Expert Comment

by:enkor
ID: 35130481
try to change this

command.Parameters.Add("@Product_ID", SqlDbType.Int);
command.Parameters["@Product_ID"].Value = ProductID;

to this

command.Parameters.Add("Product_ID", SqlDbType.Int);
command.Parameters["Product_ID"].Value = ProductID;
0
 

Author Closing Comment

by:vbnetcoder
ID: 35157643
ty
0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

728 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