0
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace iss_farmacie_spitali
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            sqlConnection1.Open();
            sqlCommand1.Parameters.AddWithValue("user",textBox1.Text);
            sqlCommand1.Parameters.AddWithValue("pass",textBox2.Text);
            sqlCommand1.CommandText = "SELECT id,parola FROM ANGAJAT WHERE id=(user) AND    parola=(pass)";
            if (sqlCommand1.ExecuteNonQuery()!=null)
                MessageBox.Show("ESTE");
            sqlConnection1.Close();
        }
    }
}

What I hope to accomplish is build a functional login. I have the database, a table named "angajati"(employees) containing id(a username practically) and parola(which is password). What I want to know it I can introduce "variables" within the SQL script text to have it run like a function and simply pass the values from my text boxes. This is what I made up from other examples but it doesn't seem to work. Could anybody give me a bit of insight upon the matter?

1

1 Answer 1

3
private void button1_Click(object sender, EventArgs e)
        {
            sqlConnection1.Open();
            sqlCommand1.Parameters.AddWithValue("@user",textBox1.Text);
            sqlCommand1.Parameters.AddWithValue("@pass",textBox2.Text);
            sqlCommand1.CommandText = "SELECT id,parola FROM ANGAJAT WHERE id='@user' AND    parola='@pass'";
            if (sqlCommand1.ExecuteNonQuery()!=null)
                MessageBox.Show("ESTE");
            sqlConnection1.Close();
        }
Sign up to request clarification or add additional context in comments.

1 Comment

You don't need quotes around the parameters in the SQL.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.