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();}
Madan ShekarRank #428 · 5.9K reputationPosted May 2, 2019, 8:34 PM EDT
Rajanikant HawaldarRank #110 · 20.4K reputationPosted May 2, 2019, 8:35 PM EDT
Amit GuptaRank #190 · 12.8K reputationPosted May 2, 2019, 8:56 PM EDT
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts