You can do it simply by finding from the countermaster2.
If you have to fetch columns from both of tables, you should use join using countermaster2.
Its your choice but here your mistake as in your code is
cmd.ExecuteScalar();
string val = string.Empty;
cmd.Parameters.AddWithValue("@Code",val);
textBox6.Text = val;
Change this part to be as
string val = textBox6.Text
cmd.Parameters.AddWithValue("@Code",val);
cmd.ExecuteScalar();
Enjoy!
Ye mera India. :-)