Solved

syntax C#

Posted on 2011-03-14
5
185 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
  • 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

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…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

747 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

13 Experts available now in Live!

Get 1:1 Help Now