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();
}
}"
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);
- Chetancmd1
should (must!) use parameters, to avoid SQL Injection. - mjwills