I have an "addstock" form and a "viewstocks" form in two different forms.
When I add the stock_no
and details in the addstock form and come back press the "refresh button " which is in the viewstock form; the new record will appear in the viewstock form.
The viewstock form has the delete button also.
When I select the row and press delete, I get this error
Must declare the scalar variable "@Stockno"
I need to call it. please help,
private void bunifuFlatButton3_Click(object sender, EventArgs e)
{
try
{
conn.Close();
conn.Open();
String DeleteQuery = "delete from Stocks_Item where Stock_code = (@Stockno)";
SqlDataAdapter execute = new SqlDataAdapter(DeleteQuery, conn);
execute.SelectCommand.ExecuteNonQuery();
MessageBox.Show("You've deleted successfully!", "Successful Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
conn.Close();
cmd.ExecuteNonQuery();
SqlDataAdapter data = new SqlDataAdapter("Select * from Stocks_Item", conn);
DataTable dt = new DataTable();
data.Fill(dt);
dataGridView1.DataSource = dt;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}