How can i edit Login Form in C# using SQL parameters?

So i have Login Form where i need to insert Name and Password from sql database, but it gets an error because my fields are nvarchar, so i'd like to edit it using sql parameters.

Code of "Enter" button:

private void button1_Click(object sender, EventArgs e)
        {
            if (DocName.Text == "" || PassTb.Text == "")
                MessageBox.Show("Enter login and password");
            else
            {
                conn.Open();
                SqlDataAdapter sda = new SqlDataAdapter("select Count(*) from Doctor where DocName='"+DocName.Text+"' and DocPass='"+PassTb.Text+"'", conn);
                DataTable dt = new DataTable();
                sda.Fill(dt);
                if (dt.Rows[0][0].ToString() == "1"){
                    Home H = new Home();
                    H.Show();
                    this.Hide();
                }
                else
                {
                    MessageBox.Show("Invalid login or password");
                }
                conn.Close();
            }
        }

I think if i use cmd.parameters.AddWithValue it will solve my problems, but i can't figure out how to do it, so i'll be glad for any help



Read more here: https://stackoverflow.com/questions/67939065/how-can-i-edit-login-form-in-c-sharp-using-sql-parameters

Content Attribution

This content was originally published by carl at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: