Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Data input in textbox question c#

$
0
0
Hello all.
I'm using this code for my login form button:
private void btnOK_Click(object sender, EventArgs e)
        {
            SqlConnection con = Program.GetConnection;
            SqlDataReader dr = null;

            try
            {
                SqlCommand cmd = new SqlCommand("SELECT * FROM tabelaZaposlenih WHERE up_ime='" +
                    txtName.Text + "' AND geslo='" + txtpassword.Text + "'", con);
                dr = cmd.ExecuteReader();
                if (dr.Read())
                {
                    Program.UserLoginName = dr.GetString(1);
                    this.Close();
                    new Form1().Show();


                }
                else
                    MessageBox.Show("Invalid username and password!");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);

            }



After login i want do display logged in user name in another forms textbox field. I would also like to get users ID, so i can create other functionalities. I understand i have to use this for putting text into textbox.

textBox1.Text = Program.UserLoginName;


But where do i put that? Only way i can get this to work is with button:

private void button1_Click(object sender, EventArgs e)
        {
            textBox1.Text = Program.UserLoginName;
        }


But that is quite useless since i nedd the program to do that on it's own. Any help would be apriciated :)
Greetings

Viewing all articles
Browse latest Browse all 51036

Trending Articles