I am getting error "Must declare scalar variable @uname and @pw". I have tried many methods but its not working. please guide me to find the issue in my belo code.
- private void button1_Click(object sender, EventArgs e)
- {
- OleDbConnection con = new OleDbConnection(@"Provider=SQLOLEDB;Data Source=DESKTOP\SQLEXPRESS;User ID=sa; Password = pwd; Initial Catalog=database; Integrated secutity=SSPI");
- con.Open();
- OleDbCommand cmd = new OleDbCommand("select Username,password from login where Username=@uname and password=@pw", con);
- OleDbDataAdapter da = new OleDbDataAdapter(cmd);
- cmd.Parameters.Clear();
- //cmd.Parameters.AddWithValue("@uname", textBox1.Text);
- //cmd.Parameters.AddWithValue("@pw", textBox1.Text);
- DataTable dt = new DataTable();
- da.Fill(dt);
- if (dt.Rows.Count > 0)
- {
- MessageBox.Show("success");
- }
- else
- {
- MessageBox.Show("incorrect");
- }
- con.Close();}
3 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Amit GuptaPosted May 3, 2019, 12:56 AM
Rajanikant HawaldarPosted May 3, 2019, 12:35 AM
Madan ShekarPosted May 3, 2019, 12:34 AM