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");
                SqlDataAdapter sda = new SqlDataAdapter("select Count(*) from Doctor where DocName='"+DocName.Text+"' and DocPass='"+PassTb.Text+"'", conn);
                DataTable dt = new DataTable();
                if (dt.Rows[0][0].ToString() == "1"){
                    Home H = new Home();
                    MessageBox.Show("Invalid login or password");

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:

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: