We help IT Professionals succeed at work.
Get Started

How can I populate this class?

Camillia asked
Last Modified: 2010-04-21
I have a class called :customer. It has ID, firstname, lastname, phone number, etc.
I have a stored proc that gets ID, firstname,lastname, phone. It doesnt get ALL the properties of customer ..just the ones I need.

I have the dataset below to read the stored proc results. How can I populate this class, I triedbut got an error that the property is read only.
foreach (DataRow row in ds.Tables[0].Rows)
                        test.EmailAddress = row[0].ToString();
DataSet ds;
        Customer test = new Customer();
       ds = new DataSet();     
        using (SqlConnection conn = Deck.Core.Database.NewConnection())
            using (SqlCommand cmd = conn.CreateCommand())
                SqlDataAdapter myAdapter = new SqlDataAdapter();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "SearchLastName";
                cmd.Parameters.Add("@name", SqlDbType.NVarChar).Value = customerName;
                    myAdapter.SelectCommand = cmd;
                    foreach (DataRow row in ds.Tables[0].Rows)
                        //test.EmailAddress = row[0].ToString();
                        //test.FirstName = row[1].ToString();
                        //test.Id = row[2].ToString();
                        //test.LastName = row[3].ToString();
                        //test.MiddleName = row[4].ToString();
                        //test.NamePrefix = row[5].ToString();
                        //test.AlternatePhoneNumber = row[6].ToString();
                        //test.PrimaryPhoneNumber = row[7].ToString();

Open in new window

Watch Question
This problem has been solved!
Unlock 1 Answer and 22 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE