SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
con.Open();
string cmdstr = "select count(*) from [Registration] where UserName'" + txtUsername.Text + "' ";
SqlCommand cmd = new SqlCommand(cmdstr, con);
int temp = Convert.ToInt32(cmd.ExecuteScalar().ToString()); //its giving error on this line.
con.Close();