Solved

syntax C#

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

920 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