One problem is that the
SqlParameterCollection.Add Method (String, Object)[
^] is obsolete. Because of this, use
AddWithValue[
^] instead. In other words
...
mycmdOptionPanel.Parameters.AddWithValue("@Device_name",LabelDeviceName.Text);
...
Also note that the parameter value must be an exact match with the value in the database. If you have case-sensitive database then even small and capital letters affect the result. If the ExecuteScalar returns no rows, the return value is null thus resulting into an exception.