I would do as below
using(SqlConnection conn = new SqlConnection(constr))
using(SqlCommand comm = new SqlCommand("SELECT COUNT(*) FROM stock1 WHERE pname =@pname and ondate =@ondate", conn))
{
comm.Parameters.AddWithValue("@pname", name);
comm.Parameters.AddWithValue("@ondate", date);
conn.Open();
int count = (int) comm .ExecuteScalar();
if(count>0)
MessageBox.Show("value already exist");
}
You have Check method, update the method to pass name and ondate as method parameters.
nested database queries makes difficult to find the issues and while using readers and commands with same sql connection. You better refactor your code and try to apply below best practices.
-Don't share the connection objects, create one and use it, after you can properly dispose the connection. (wrap the connection, command etc with using blocks, it will automatically dispose the object)
- use parameters, it is safe and you are not open for sql injection attacks
- you can use ExecuteScalar method in this case to check whether row exist with given values. ( learn about methods available with which methods most suitable for your requirements)