how to extract data to C# variable from database
<p>while trying to fetch value to c# variable from select query, got error</p>

<pre><code>using (var cmd = new SqlCommand("select group1 from product where productname = @pn)", con))
{
    cmd.Parameters.Add(new SqlParameter("@pn", TextBox1.Text));

    reader = cmd.ExecuteReader();//got error

    while (reader.Read())
    {
        data = Convert.ToInt32(reader);//got error
    }    
}
</code></pre>