yumo
yumo
Explore posts from servers
CC#
Created by yumo on 2/23/2023 in #help
❔ login system saves data from user
Something like this
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();

SqlCommand command = new SqlCommand("SELECT realname, id, nivel FROM Users WHERE username = @username AND password = @password", connection);
command.Parameters.AddWithValue("@username", username);
command.Parameters.AddWithValue("@password", password);

SqlDataReader reader = command.ExecuteReader();

if (reader.HasRows)
{
reader.Read();
int id = reader.GetInt32(0);
string realname = reader.GetString(1);
string nivel = reader.GetString(2);

// create a new User object with the retrieved data
loggedInUser = new UserData(id, realname, nivel);

// open the main menu form
MainMenu mainMenu = new MainMenu(loggedInUser);
mainMenu.Show();
this.Hide();
}
else
{
// invalid credentials, display error message
MessageBox.Show("Credenciais inválidas!");
}

reader.Close();
}
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();

SqlCommand command = new SqlCommand("SELECT realname, id, nivel FROM Users WHERE username = @username AND password = @password", connection);
command.Parameters.AddWithValue("@username", username);
command.Parameters.AddWithValue("@password", password);

SqlDataReader reader = command.ExecuteReader();

if (reader.HasRows)
{
reader.Read();
int id = reader.GetInt32(0);
string realname = reader.GetString(1);
string nivel = reader.GetString(2);

// create a new User object with the retrieved data
loggedInUser = new UserData(id, realname, nivel);

// open the main menu form
MainMenu mainMenu = new MainMenu(loggedInUser);
mainMenu.Show();
this.Hide();
}
else
{
// invalid credentials, display error message
MessageBox.Show("Credenciais inválidas!");
}

reader.Close();
}
But displaying this error: System.InvalidCastException: 'The specific conversion isnt valid.' on this line: int id = reader.GetInt32(0);
15 replies
CC#
Created by yumo on 2/23/2023 in #help
❔ login system saves data from user
This? SELECT realname FROM Users WHERE username = @username AND password = @password ?
15 replies
CC#
Created by yumo on 2/23/2023 in #help
❔ login system saves data from user
idk hwo to work with dapper mb
15 replies
CC#
Created by yumo on 2/23/2023 in #help
❔ login system saves data from user
This is what i have on MainMenu form
private UserData loggedInUser;
public MainMenu(UserData user)
{
InitializeComponent();
loggedInUser = user;

// display the logged-in user's first name on the lblNomeUtilizador label
lblNomeUtilizador.Text = loggedInUser.RealName;
}
private UserData loggedInUser;
public MainMenu(UserData user)
{
InitializeComponent();
loggedInUser = user;

// display the logged-in user's first name on the lblNomeUtilizador label
lblNomeUtilizador.Text = loggedInUser.RealName;
}
And this is my UserData class to save the information of the user
public class UserData
{
public int UserId { get; set; }
public string RealName { get; set; }
public string Nivel { get; set; }

public UserData(int id, string realname, string nivel)
{
UserId = id;
RealName = realname;
Nivel = nivel;
}

}
public class UserData
{
public int UserId { get; set; }
public string RealName { get; set; }
public string Nivel { get; set; }

public UserData(int id, string realname, string nivel)
{
UserId = id;
RealName = realname;
Nivel = nivel;
}

}
15 replies
CC#
Created by yumo on 2/16/2023 in #help
❔ SELECT MAX ID from textbox
i think im gonna rest a lil bit and we can have a look afterwards not feeling quite good
447 replies
CC#
Created by yumo on 2/16/2023 in #help
❔ SELECT MAX ID from textbox
true
447 replies
CC#
Created by yumo on 2/16/2023 in #help
❔ SELECT MAX ID from textbox
idk maybe im just confused, tired , idk i slept 3 hours
447 replies
CC#
Created by yumo on 2/16/2023 in #help
❔ SELECT MAX ID from textbox
but the thing is i've never coded like this before
447 replies
CC#
Created by yumo on 2/16/2023 in #help
❔ SELECT MAX ID from textbox
yeah
447 replies
CC#
Created by yumo on 2/16/2023 in #help
❔ SELECT MAX ID from textbox
I was used to one thing and now it's all very complicated
447 replies
CC#
Created by yumo on 2/16/2023 in #help
❔ SELECT MAX ID from textbox
this is a new world for me ngl
447 replies
CC#
Created by yumo on 2/16/2023 in #help
❔ SELECT MAX ID from textbox
447 replies
CC#
Created by yumo on 2/16/2023 in #help
❔ SELECT MAX ID from textbox
how do i use dapper then im fully confused
447 replies
CC#
Created by yumo on 2/16/2023 in #help
❔ SELECT MAX ID from textbox
its missing some asseblys, for the login system i need Syte.Data.SqlClietn; But i need sum more
447 replies
CC#
Created by yumo on 2/16/2023 in #help
❔ SELECT MAX ID from textbox
yeah i saw that
447 replies
CC#
Created by yumo on 2/16/2023 in #help
❔ SELECT MAX ID from textbox
all i get is for websites :/
447 replies
CC#
Created by yumo on 2/16/2023 in #help
❔ SELECT MAX ID from textbox
i was trying to search anything online or a video i could follow to do this but im lost
447 replies
CC#
Created by yumo on 2/16/2023 in #help
❔ SELECT MAX ID from textbox
should i create a class to make my functions there?
447 replies
CC#
Created by yumo on 2/16/2023 in #help
❔ SELECT MAX ID from textbox
i installed the nuget allready
447 replies
CC#
Created by yumo on 2/16/2023 in #help
❔ SELECT MAX ID from textbox
447 replies