I need a method that takes the information of a selected row (with another method, already written (SQL Count)) and puts it in an object called Gebruiker (user).
I already have a method that puts the information from an object in to the database with parameters, but this doesn't work for the other way.
This is my object class:
namespace BurnThatFat
{
class Gebruikerklasse
{
public string Naam;
public string Achternaam;
public int Leeftijd;
public string Geslacht;
public int Huidiggewicht;
public int Streefgewicht;
public string Gebruikersnaam;
public string Wachtwoord;
public override string ToString()
{
return Naam;
}
}
}
and this is the method that puts the information from the object to the database:
public void SignUp(string commandText, Gebruikerklasse gebruiker)
{
// nieuwe connectie maken
// ontvangt de query vanuit 'buttonclick' en voert hem hier uit
// als ExecuteNonQuery niet kan worden uitgevoerd is er iets fout gegaan. D.m.v een bool moet hij dan een bericht tonen
using (SqlConnection conn = new SqlConnection(connectionString))
using (SqlCommand cmd = new SqlCommand(commandText, conn))
{
conn.Open();
cmd.Parameters.AddWithValue("@Naam", gebruiker.Naam);
cmd.Parameters.AddWithValue("@Achternaam", gebruiker.Achternaam);
cmd.Parameters.AddWithValue("@Leeftijd", gebruiker.Leeftijd);
cmd.Parameters.AddWithValue("@Geslacht", gebruiker.Geslacht);
cmd.Parameters.AddWithValue("@Huidiggewicht", gebruiker.Huidiggewicht);
cmd.Parameters.AddWithValue("@Streefgewicht", gebruiker.Streefgewicht);
cmd.Parameters.AddWithValue("@Gebruikersnaam", gebruiker.Gebruikersnaam);
cmd.Parameters.AddWithValue("@Wachtwoord", gebruiker.Wachtwoord);
int a = cmd.ExecuteNonQuery();
if (a == 1)
{
Success = true;
}
else if (a == -1)
{
Success = false;
}
conn.Close();
}
}
So how do I have to do this? I don't know how to google this really. I think I'm using the wrong words while googling, because im getting non related things...
Edit: added screenshots
So I need the information in this table: http://prnt.sc/dsg95v
To be stored in this object: http://prnt.sc/dsghl1
I already have code (above) that returns the information from the object to the table. I do that with parameters.
I really don't know where to start with database to object...
Edit again: something like this:
public void DatabaseTransferObject(string commandText, Gebruikerklasse gebruiker)
{
using (SqlConnection conn = new SqlConnection(connectionString))
using (SqlCommand cmd = new SqlCommand(commandText, conn))
{
conn.Open();
gebruiker.Naam = //code to get Naam (name) from table Gebruiker (user);
gebruiker.Leeftijd = //code to get Leeftijd(age) from table Gebruiker (user);
conn.Close();
}
}
This the SQL code to get all the information from the row with the given @username
"Select * from Gebruiker where Gebruikersnaam = @Gebruikersnaam;
Gebruikerklassehas no properties, just public members.