Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7050791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:11:13+00:00 2026-05-28T03:11:13+00:00

In a nutshell: I have some database table data that I want to populate

  • 0

In a nutshell: I have some database table data that I want to populate c# structs with.

For example:

struct Phone
{
    public int PhoneID;
    public string Number;
}
struct Patient
{
    public Phone WorkPhone;
}

And the SQL tables look like this:

Patient table:  
    Patient ID, Patient Name, etc.  
Phone table:  
    PhoneID, Number, Phone Type etc.  

Basically the structs are mirrors of the SQL tables.

I have the primary key (PhoneID), that I am passing through a select statement. So I will only retrieve one row in the case of the patient or up to 5 rows for the Phone table (They can have Work, Cell, Home, etc).

I don’t have a great way to stuff this table into a struct easily. What I am doing now is one by one. You can see for hundreds of variables per patient, it’s a very tedious and highly code intensive process. Is there some way, maybe I can have a variable in the variable name, for example if the column name is Phone then it would stuff the Phone variable. Hope that makes sense.

query = "SELECT * FROM Phone p WHERE p.StatusID = 'A' AND ObjectTypeID = 'PA' AND ObjectID = '" + PatientID.ToString() + "'";
SqlDataAdapter a1 = new SqlDataAdapter(query, dataConnection);
DataTable t1 = new DataTable();
a1.Fill(t1);
DataTableReader r1 = t.CreateDataReader();
//object value = null;
while (reader.Read())
{
    for (int i = 0; i < r1.FieldCount; i++)
    {
        if (!r1.IsDBNull(i))
        {
            if reader.GetValue(i)
            switch (r1.GetName(i))
            {
                case "PhoneID": { pr.HomePhone.PhoneID = (int)reader.GetValue(i); break; }
                case "PhoneTypeID": { pr.HomePhone.PhoneTypeID = (string)reader.GetValue(i); break; }
                case "ObjectID": { pr.HomePhone.ObjectID = (int)reader.GetValue(i); break; }
                case "ObjectTypeID": { pr.HomePhone.ObjectTypeID = (string)reader.GetValue(i); break; }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T03:11:14+00:00Added an answer on May 28, 2026 at 3:11 am

    It may be that you need an ORM like NHibernate, Lightspeed or Entity Framework.

    If they’d be overkill, check out one of the new mini ORM-like libraries like Massive.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In a nutshell , I want to have different faces for some types of
I have some nested tables that I want to hide/show upon a click on
I have an ASP.NET user control that I want to write some dynamic Javascript
In a nutshell, I have a solution that builds fine in the IDE, and
I've got a program that in a nutshell reads values from a SQL database
I have some code that watches the event log for entry written events and
I have a WCF service that does some document conversions and returns the document
I think I have got some grasp over basic WPF fundaes. Now I want
Here are the specs that I'm trying to implement in a nutshell: 1) Some
We currently have a 10 year old nasty, spaghetti-code-style SQL Server database that we

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.