Click here to Skip to main content
15,922,015 members
Home / Discussions / C#
   

C#

 
GeneralDomain Driven Design Quickly - free ebook Pin
DaveyM6917-Jan-09 2:22
professionalDaveyM6917-Jan-09 2:22 
GeneralRe: Domain Driven Design Quickly - free ebook Pin
CodingYoshi17-Jan-09 13:17
CodingYoshi17-Jan-09 13:17 
AnswerRe: Business Objects Pin
Mark Graham26-Feb-09 23:43
Mark Graham26-Feb-09 23:43 
Questiondisplay data from a database in a label Pin
ferronrsmith16-Jan-09 10:21
ferronrsmith16-Jan-09 10:21 
AnswerRe: display data from a database in a label Pin
Alaric_16-Jan-09 10:25
professionalAlaric_16-Jan-09 10:25 
GeneralRe: display data from a database in a label Pin
ferronrsmith16-Jan-09 11:24
ferronrsmith16-Jan-09 11:24 
GeneralRe: display data from a database in a label Pin
ferronrsmith16-Jan-09 11:25
ferronrsmith16-Jan-09 11:25 
GeneralRe: display data from a database in a label Pin
CodingYoshi16-Jan-09 12:50
CodingYoshi16-Jan-09 12:50 
Here is one way, but there are many:

public class User
{
private string _firstName;
private string _lastName;
private string _id; // or int not sure what type yours is

public void Load(string id)
{
UserManager manager = new UserManager();
manager.Retrieve(this);
}
// properties and other methods

}

public class UserManager()
{
public void Retrieve(User userToRetrieve)
{
SqlCommand cmd = new SqlCommand();
cmd.Text = "SELECT FirstName, LastName FROM UserTable WHERE UserID = '" + id + "'";
// Here use an adapter and fill a DataTable
// If the DataTable has rows then assing the proper columns to the userToRetrieve object
// If no rows then throw an exception to advise no User was found with the given id.
}
}

You UI code can be something like this:
User aUser = new User();
string id = "123";
try
{
aUser.Load(id);
this.LabelID.Text = aUser.ID;
this.LabelFirstName.Text = aUser.FirstName;
this.LabelLastName.Text = aUser.LastName;
}
catch(SomeException ex)
{
MessageBox.Show(ex.Message);
}

If you still can not do it then buy a book on C#. Please note this code might have errors but it is just to give you an idea.
QuestionString representation of an object's property name Pin
Alaric_16-Jan-09 10:11
professionalAlaric_16-Jan-09 10:11 
AnswerRe: String representation of an object's property name Pin
TommyTomToms16-Jan-09 10:44
TommyTomToms16-Jan-09 10:44 
GeneralRe: String representation of an object's property name Pin
Alaric_16-Jan-09 10:55
professionalAlaric_16-Jan-09 10:55 
GeneralRe: String representation of an object's property name Pin
Jon Rista16-Jan-09 11:47
Jon Rista16-Jan-09 11:47 
GeneralRe: String representation of an object's property name Pin
Alaric_16-Jan-09 13:43
professionalAlaric_16-Jan-09 13:43 
QuestionHi peoples, Pin
Hema Bairavan16-Jan-09 7:07
Hema Bairavan16-Jan-09 7:07 
AnswerRe: Hi peoples, Pin
Thomas Stockwell16-Jan-09 7:47
professionalThomas Stockwell16-Jan-09 7:47 
QuestionNewbie question about TreeNodeCollection vs TreeNode Pin
Rafone16-Jan-09 5:11
Rafone16-Jan-09 5:11 
AnswerRe: Newbie question about TreeNodeCollection vs TreeNode Pin
Wendelius16-Jan-09 7:54
mentorWendelius16-Jan-09 7:54 
GeneralRe: Newbie question about TreeNodeCollection vs TreeNode Pin
Rafone16-Jan-09 9:17
Rafone16-Jan-09 9:17 
GeneralRe: Newbie question about TreeNodeCollection vs TreeNode Pin
Wendelius16-Jan-09 9:26
mentorWendelius16-Jan-09 9:26 
GeneralRe: Newbie question about TreeNodeCollection vs TreeNode Pin
Rafone16-Jan-09 10:00
Rafone16-Jan-09 10:00 
GeneralRe: Newbie question about TreeNodeCollection vs TreeNode Pin
Wendelius16-Jan-09 10:05
mentorWendelius16-Jan-09 10:05 
GeneralRe: Newbie question about TreeNodeCollection vs TreeNode Pin
Rafone16-Jan-09 10:49
Rafone16-Jan-09 10:49 
QuestionWhat's your suggestion ? Pin
Mohammad Dayyan16-Jan-09 4:56
Mohammad Dayyan16-Jan-09 4:56 
AnswerRe: What's your suggest ? Pin
TylerBrinks16-Jan-09 4:59
TylerBrinks16-Jan-09 4:59 
AnswerRe: What's your suggest ? Pin
User 665816-Jan-09 5:40
User 665816-Jan-09 5:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.