1

I created a public class and wrote a public constructor with parameters like:

public Patient(SqlDataReader reader, string p) {
        if (p == "L") {
            Name = reader[0].ToString();
        }
        else { }
    }

then I used this constructor like

SqlDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    Patient myP(reader, "L");                    
                }

Then during debug, I got the error: Error 49 Expected ; or = (cannot specify constructor arguments in declaration)

Where is the problem and how can I fix it?

1
  • I should say: you might find it more effective to use tools like ORMs or micro-ORMs to populate the objects; the "use a data-reader to fill an object" is pretty-much a solved problem Commented May 29, 2013 at 6:50

2 Answers 2

5

That syntax simply isn't valid; try:

Patient myP = new Patient(reader, "L");

or (identical result):

var myP = new Patient(reader, "L");
Sign up to request clarification or add additional context in comments.

Comments

1

You should use constructor with new operator like;

Patient p = new Patient(reader, "L");

Your syntax is invalid for C#.

From new Operator (C# Reference)

Used to create objects and invoke constructors.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.