?
Solved

syntax C#

Posted on 2011-03-14
5
Medium Priority
?
194 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 2000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

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…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month17 days, 9 hours left to enroll

830 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