syntax C#

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

vbnetcoderAsked:
Who is Participating?
 
Carl TawnConnect With a Mentor Systems and Integration DeveloperCommented:
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
 
Carl TawnSystems and Integration DeveloperCommented:
That would suggest you are trying to define your method outside of a class, which isn't allowed.
0
 
vbnetcoderAuthor Commented:
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
 
enkorCommented:
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
 
vbnetcoderAuthor Commented:
ty
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.