0
votes

Getting this error >No value given for one or more required parameters

"protected void Button1_Click(object sender, EventArgs e) { OleDbConnection con = new OleDbConnection();

    con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Server.MapPath("~/Database/registration.accdb");
    con.Open(); // connection open  
    cmd = new OleDbCommand("SELECT * FROM userdata where email=@email");
    cmd.Parameters.AddWithValue("@email", TextBox1.Text);
    adp = new OleDbDataAdapter(cmd.CommandText, con);
    adp.Fill(dt);

    if (dt.Rows.Count != 0)
    {
        String myGUID = Guid.NewGuid().ToString();
        int uid = Convert.ToInt32(dt.Rows[0][1]);
        OleDbCommand cmd1 =new OleDbCommand("Insert into forgotpass(id,uid,requestdatetime)values('"+myGUID+"','"+uid+"',GETDATE())",con);
        cmd1.ExecuteNonQuery();
    }
}"
1
new OleDbDataAdapter(cmd.CommandText, con); is setting the commandtext for Adapter but it does not set the parameter value which is in the command itself. You should do following.. cmd.Connection = con; new OleDbDataAdapter(cmd); - Chetan
cmd1 should (must!) use parameters, to avoid SQL Injection. - mjwills

1 Answers

0
votes

Looks like your command object doesn't know which connection to use as You have not specified your connection as Active Connection for your command.

Use "command.Connection = Con;" and try.