This method is used to fill the datatable's row value into an obejct and will return the object.
So after this code executing completely, the result will be.
getUser object
This object's property has the row's value.
id = 1 username = aaa ...
At last, we will return this object to somewhere to execute other codes according to this object.
Best Regards,
Brando
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Member
4 Points
130 Posts
REG loading details from db to textboxes Db values are passed through data transfer object
May 07, 2013 12:03 AM|Pepin|LINK
HI
Need Explanation
public UserDto GetUserByID(int UserId)
{
try
{
UserDto getUser = null;
Command = DataBase.GetStoredProcCommand("GetUserByID");
DataBase.AddInParameter(Command, "@UserId", DbType.Int32, UserId);
DataSet resultDataSet = ExecuteDataSet();
if (resultDataSet != null && resultDataSet.Tables.Count > 0 && resultDataSet.Tables[0].Rows.Count > 0)
{
getUser = TranslateUserDataRowToEntity(resultDataSet.Tables[0].Rows[0]);
}
return getUser;
}
catch
{
throw;
}
}
private UserDto TranslateUserDataRowToEntity(DataRow dataRow)
{
UserDto getUser = new UserDto();
getUser.ID = Convert.ToInt32(dataRow["id"]);
getUser.Username = Convert.ToString(dataRow["username"]);
getUser.FirstName = Convert.ToString(dataRow["first_name"]);
getUser.LastName = Convert.ToString(dataRow["last_name"]);
getUser.Password = Convert.ToString(dataRow["password"]);
getUser.Email = Convert.ToString(dataRow["email"]);
return getUser;
}
Star
9831 Points
3120 Posts
Re: REG loading details from db to textboxes Db values are passed through data transfer object
Oct 25, 2016 11:58 AM|Brando ZWZ|LINK
Hi Pepin,
According to your description and codes, I couldn't understand your requirement clearly.
Do you mean you want to know how this code works?
I think this codes is used to search user from database according to userID.
But it has a Translate method translate the table's row value into a UserDto object.
Let's see this codes:
1.
This codes is used to search user form database and fill the result into a dataset.
After this codes executing completely, the dataset will have value.
For example:
Result like below:
2.
This codes firstly adjust the dataset has the value, if the dataset has value then call TranslateUserDataRowToEntity method.
Note:Since you just search one user, so the datatabls will just have one row.
3.
This method is used to fill the datatable's row value into an obejct and will return the object.
So after this code executing completely, the result will be.
At last, we will return this object to somewhere to execute other codes according to this object.
Best Regards,
Brando