Hello! So i have a Login Form and i have to insert Login and Password through SqlDataAdapter, but i don't know how to do it using TextBox of Login And Password, and i get the next error:
System.Data.SqlClient.SqlException: "The parameterized query '(@DocName nvarchar(50),@DocPass nvarchar(50))SELECT * FROM Docto' expects the parameter '@DocName', which was not supplied."
What I have tried:
Code of the form:
<pre>public static SqlDataAdapter CreateCustomerAdapter(SqlConnection conn)
{
SqlDataAdapter adapter = new SqlDataAdapter();
SqlCommand command = new SqlCommand("SELECT * FROM Doctor " +
"WHERE DocName = @DocName AND DocPass = @DocPass", conn);
command.Parameters.Add("@DocName", SqlDbType.NVarChar, 50);
command.Parameters.Add("@DocPass", SqlDbType.NVarChar, 50);
adapter.SelectCommand = command;
return adapter;
}
private void button1_Click(object sender, EventArgs e)
{
conn.Open();
SqlDataAdapter sda = CreateCustomerAdapter(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 in the next lines
<pre>command.Parameters.Add("@DocName", SqlDbType.NVarChar, 50);
command.Parameters.Add("@DocPass", SqlDbType.NVarChar, 50);
i should replace
SqlDbType.NVarChar, 50
with Textboxes DocName.Text and DocPassword.Text, but it doesn't seem to work.