W
WJ
..Net Experts,
I have this concept described below:
1. I have a large (4K+) data record called Health_R. This record also
contains Text/memo fields and Image.
2. The record layout is below:
*******************
//My beloved c#
//
using System;
namespace Health.HealthRec
{
[Serializable]
public class Health_R
{
private string PatientName; //NVarChar(80)
private string PresentIllness; //ntext --Memo Field (Filled by
Nurses/Doctor
private string PatientPresentImage; //Image --Patient Picture
private string DOB; //DateTime
public Health_R()
{
}
}
}
*********************
3. In my Asp.Net form, I "new" the above structure as: private Health_R
ph=new Health_R();
4. I then read the data (say one record) into my DataSet.
5. I then go into a for loop to extract each field from the returned DataSet
as follow:
string fn="";
for(int i=0;i<DataSet.Tables[0].Columns.Count;i++)
{
fn=DataSet.Tables[0].Columns.ColumnName;
if(fn=="PatientName") //This is tough - I want to get rid of
this hard code
{
ph.PatientName=DataSet.Tables[0].Rows[0][fn].ToString();
}
else if...
}
***********
My question is: How do I assign each field to instance "ph" using variable
"fn" (contains the name of the database table column) as I could with the
DataSet.Tables[0].Rows[0][fn].ToString() without hardcoding all the columns
names ?
I really like this concept because I can do this at runtime without changing
the source codes in the event the database structure is changed.
Thanks for your help,
BTW: I read about "Reflection" but could not find any reference about it.
John
I have this concept described below:
1. I have a large (4K+) data record called Health_R. This record also
contains Text/memo fields and Image.
2. The record layout is below:
*******************
//My beloved c#
//
using System;
namespace Health.HealthRec
{
[Serializable]
public class Health_R
{
private string PatientName; //NVarChar(80)
private string PresentIllness; //ntext --Memo Field (Filled by
Nurses/Doctor
private string PatientPresentImage; //Image --Patient Picture
private string DOB; //DateTime
public Health_R()
{
}
}
}
*********************
3. In my Asp.Net form, I "new" the above structure as: private Health_R
ph=new Health_R();
4. I then read the data (say one record) into my DataSet.
5. I then go into a for loop to extract each field from the returned DataSet
as follow:
string fn="";
for(int i=0;i<DataSet.Tables[0].Columns.Count;i++)
{
fn=DataSet.Tables[0].Columns.ColumnName;
if(fn=="PatientName") //This is tough - I want to get rid of
this hard code
{
ph.PatientName=DataSet.Tables[0].Rows[0][fn].ToString();
}
else if...
}
***********
My question is: How do I assign each field to instance "ph" using variable
"fn" (contains the name of the database table column) as I could with the
DataSet.Tables[0].Rows[0][fn].ToString() without hardcoding all the columns
names ?
I really like this concept because I can do this at runtime without changing
the source codes in the event the database structure is changed.
Thanks for your help,
BTW: I read about "Reflection" but could not find any reference about it.
John